Download src/middleware/auth.js from TwanAPI/trsstapi: direct link, hf CLI and curl.
- Browser
- Download file 543 Bytes
-
https://huggingface.co/spaces/TwanAPI/trsstapi/resolve/aaff83dd1affe87e82019cb318c593e9d15fa2fd/src/middleware/auth.js
- Command line
-
hf download hf://spaces/TwanAPI/trsstapi@aaff83dd1affe87e82019cb318c593e9d15fa2fd/src/middleware/auth.js
-
curl -L -o auth.js https://huggingface.co/spaces/TwanAPI/trsstapi/resolve/aaff83dd1affe87e82019cb318c593e9d15fa2fd/src/middleware/auth.js
543 Bytes
| import jwt from "jsonwebtoken"; | |
| import { User } from "../models/User.js"; | |
| import { JWT_CONFIG } from "../config/security.js"; | |
| export async function auth(req, res, next) { | |
| const token = req.headers.authorization?.split(" ")[1]; | |
| if (!token) return res.sendStatus(401); | |
| try { | |
| const payload = jwt.verify(token, process.env.JWT_SECRET, JWT_CONFIG); | |
| const user = await User.findById(payload.id); | |
| if (!user || user.deletedAt) return res.sendStatus(401); | |
| req.user = user; | |
| next(); | |
| } catch { | |
| res.sendStatus(401); | |
| } | |
| } | |