Download server/src/middleware/auth.js from soxogvv/MNEMO: direct link, hf CLI and curl.
- Browser
- Download file 475 Bytes
-
https://huggingface.co/spaces/soxogvv/MNEMO/resolve/main/server/src/middleware/auth.js
- Command line
-
hf download hf://spaces/soxogvv/MNEMO/server/src/middleware/auth.js
-
curl -L -o auth.js https://huggingface.co/spaces/soxogvv/MNEMO/resolve/main/server/src/middleware/auth.js
475 Bytes
| import jwt from "jsonwebtoken"; | |
| import { env } from "../config/env.js"; | |
| export function requireAuth(req, res, next) { | |
| const header = req.headers.authorization || ""; | |
| const token = header.startsWith("Bearer ") ? header.slice(7) : null; | |
| if (!token) { | |
| return res.status(401).json({ error: "Missing token" }); | |
| } | |
| try { | |
| req.user = jwt.verify(token, env.jwtSecret); | |
| return next(); | |
| } catch { | |
| return res.status(401).json({ error: "Invalid token" }); | |
| } | |
| } | |