| 152 | * `/refresh`, `/mfa/status`), reach for `tryAuth` instead. |
| 153 | */ |
| 154 | export const requireAuth = () => |
| 155 | new Elysia() |
| 156 | .use(createJWTConfig()) |
| 157 | .derive( |
| 158 | async ({ |
| 159 | jwt: jwtPlugin, |
| 160 | cookie, |
| 161 | }): Promise<{ user: IUser; accountId: string }> => { |
| 162 | const session = await verifyAuthCookie( |
| 163 | jwtPlugin, |
| 164 | cookie[AUTH_COOKIE_NAME]?.value |
| 165 | ); |
| 166 | |
| 167 | if (session === null) { |
| 168 | throw ApiErrors.unauthorized("Missing authentication cookie"); |
| 169 | } |
| 170 | |
| 171 | return session; |
| 172 | } |
| 173 | ); |
| 174 | |
| 175 | /** |
| 176 | * Best-effort auth guard. Resolves the session if one is presented and |