Download server/middleware/auth.js from eznd/bao: direct link, hf CLI and curl.
- Browser
- Download file 610 Bytes
-
https://huggingface.co/spaces/eznd/bao/resolve/main/server/middleware/auth.js
- Command line
-
hf download hf://spaces/eznd/bao/server/middleware/auth.js
-
curl -L -o auth.js https://huggingface.co/spaces/eznd/bao/resolve/main/server/middleware/auth.js
610 Bytes
| const jwt = require('jsonwebtoken'); | |
| function authenticateToken(req, res, next) { | |
| const authHeader = req.headers['authorization']; | |
| const token = authHeader && authHeader.split(' ')[1]; // Bearer TOKEN | |
| if (token == null) { | |
| return res.sendStatus(401); // Unauthorized | |
| } | |
| jwt.verify(token, process.env.JWT_SECRET, (err, user) => { | |
| if (err) { | |
| return res.sendStatus(403); // Forbidden (invalid token) | |
| } | |
| req.user = user; // Attach decoded user payload to the request | |
| next(); | |
| }); | |
| } | |
| module.exports = authenticateToken; | |