Add Docker build workflow and mobile application
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
const jwt = require('jsonwebtoken');
|
||||
require('dotenv').config();
|
||||
|
||||
const JWT_SECRET = process.env.JWT_SECRET;
|
||||
|
||||
// Middleware to verify JWT token
|
||||
const authMiddleware = (req, res, next) => {
|
||||
const auth = req.headers.authorization;
|
||||
if (!auth || !auth.startsWith('Bearer ')) {
|
||||
return res.status(401).json({ error: 'missing_token' });
|
||||
}
|
||||
|
||||
const token = auth.slice(7);
|
||||
try {
|
||||
const payload = jwt.verify(token, JWT_SECRET);
|
||||
req.user = payload;
|
||||
next();
|
||||
} catch (err) {
|
||||
return res.status(401).json({ error: 'invalid_token' });
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = { authMiddleware };
|
||||
Reference in New Issue
Block a user