Spaces:
Sleeping
Sleeping
Download backend/src/middleware/auth.middleware.ts from simhaa-hat/generated-bill: direct link, hf CLI and curl.
- Browser
- Download file 512 Bytes
-
https://huggingface.co/spaces/simhaa-hat/generated-bill/resolve/main/backend/src/middleware/auth.middleware.ts
- Command line
-
hf download hf://spaces/simhaa-hat/generated-bill/backend/src/middleware/auth.middleware.ts
-
curl -L -o auth.middleware.ts https://huggingface.co/spaces/simhaa-hat/generated-bill/resolve/main/backend/src/middleware/auth.middleware.ts
512 Bytes
| import { Response, NextFunction } from 'express'; | |
| import { verifyToken } from '../config/jwt'; | |
| export const protect = (req: any, res: any, next: NextFunction) => { | |
| const token = req.headers.authorization?.split(' ')[1]; | |
| if (!token) { | |
| return res.status(401).json({ message: 'Auth token missing' }); | |
| } | |
| try { | |
| const decoded = verifyToken(token); | |
| req.user = decoded; | |
| next(); | |
| } catch (error) { | |
| res.status(401).json({ message: 'Invalid token' }); | |
| } | |
| }; | |