( token: string, env: Env, )
| 18 | } |
| 19 | |
| 20 | export async function verifyAuthToken( |
| 21 | token: string, |
| 22 | env: Env, |
| 23 | ): Promise<AuthPayload> { |
| 24 | const secret = new TextEncoder().encode(env.JWT_SECRET_KEY); |
| 25 | const { payload } = await jwtVerify(token, secret); |
| 26 | return { |
| 27 | email: typeof payload.email === "string" ? payload.email : undefined, |
| 28 | sub: typeof payload.sub === "string" ? payload.sub : undefined, |
| 29 | }; |
| 30 | } |
| 31 | |
| 32 | export async function requireAuthorizedRequest( |
| 33 | request: Request, |
no test coverage detected