implemented a simple backend for mobile banking

This commit is contained in:
2025-06-02 13:24:10 +05:30
commit c350c591f6
26 changed files with 4060 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
const { verifyToken } = require('../util/jwt');
const { logger } = require('../util/logger');
function auth(req, res, next) {
const authHeader = req.headers.authorization;
if (!authHeader || !authHeader.startsWith('Bearer ')) {
return res
.status(401)
.json({ error: 'missing or malformed authorization header' });
}
const token = authHeader.split(' ')[1];
try {
const payload = verifyToken(token);
req.user = payload;
next();
} catch (err) {
logger.error(err, 'error verifying token');
return res.status(401).json({ error: 'invalid or expired token' });
}
}
module.exports = auth;