(req: Request, res: Response, next: NextFunction)
| 107 | } |
| 108 | |
| 109 | requireAuth(req: Request, res: Response, next: NextFunction): void { |
| 110 | const user = this.authenticate(req as unknown as IncomingMessage); |
| 111 | if (!user) { |
| 112 | const accept = req.headers["accept"] ?? ""; |
| 113 | if (accept.includes("application/json")) { |
| 114 | res.status(401).json({ error: "Unauthorized" }); |
| 115 | } else { |
| 116 | res.redirect(`/auth/login?next=${encodeURIComponent(req.originalUrl)}`); |
| 117 | } |
| 118 | return; |
| 119 | } |
| 120 | (req as AuthenticatedRequest).user = user; |
| 121 | next(); |
| 122 | } |
| 123 | |
| 124 | // ── Internals ───────────────────────────────────────────────────────────── |
| 125 |
nothing calls this directly
no test coverage detected