Spaces:
Running
Running
feat: implement core backend POS API with authentication, role-based access control, menu management, and order processing logic.
1e480b5 Download src/middleware/authGuard.js from aliroohan179/face: direct link, hf CLI and curl.
- Browser
- Download file 773 Bytes
-
https://huggingface.co/spaces/aliroohan179/face/resolve/main/src/middleware/authGuard.js
- Command line
-
hf download hf://spaces/aliroohan179/face/src/middleware/authGuard.js
-
curl -L -o authGuard.js https://huggingface.co/spaces/aliroohan179/face/resolve/main/src/middleware/authGuard.js
773 Bytes
| const jwt = require('jsonwebtoken'); | |
| const User = require('../models/User'); | |
| const authGuard = async (req, res, next) => { | |
| const header = req.headers.authorization; | |
| if (!header || !header.startsWith('Bearer ')) { | |
| return res.status(401).json({ message: 'No token, authorisation denied' }); | |
| } | |
| const token = header.split(' ')[1]; | |
| try { | |
| const decoded = jwt.verify(token, process.env.JWT_SECRET); | |
| const user = await User.findById(decoded.id).select('-password -adminPin'); | |
| if (!user || !user.active) { | |
| return res.status(401).json({ message: 'User not found or deactivated' }); | |
| } | |
| req.user = user; | |
| next(); | |
| } catch (err) { | |
| return res.status(401).json({ message: 'Token invalid or expired' }); | |
| } | |
| }; | |
| module.exports = authGuard; | |