( req: express.Request, _?: express.Response, next?: express.NextFunction, )
| 98 | * Throw an error if not authorized. Call `next` if provided. |
| 99 | */ |
| 100 | export const ensureAuthenticated = async ( |
| 101 | req: express.Request, |
| 102 | _?: express.Response, |
| 103 | next?: express.NextFunction, |
| 104 | ): Promise<void> => { |
| 105 | const isAuthenticated = await authenticated(req) |
| 106 | if (!isAuthenticated) { |
| 107 | throw new HttpError("Unauthorized", HttpCode.Unauthorized) |
| 108 | } |
| 109 | if (next) { |
| 110 | next() |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * Return true if authenticated via cookies. |
no test coverage detected