(token: string)
| 15 | } |
| 16 | |
| 17 | export const verifyJWT = async (token: string): Promise<JWTPayload | null> => { |
| 18 | const secret = process.env.JWT_SECRET || ''; |
| 19 | |
| 20 | try { |
| 21 | const jwk = await importJWK({ k: secret, alg: 'HS256', kty: 'oct' }); |
| 22 | const { payload } = await jwtVerify(token, jwk); |
| 23 | |
| 24 | return payload; |
| 25 | } catch (error) { |
| 26 | console.error('Invalid token:', error); |
| 27 | return null; |
| 28 | } |
| 29 | }; |
| 30 | |
| 31 | export const withMobileAuth = async (req: RequestWithUser) => { |
| 32 | if (req.headers.get('Auth-Key')) { |