1
0
Fork 0
mirror of https://github.com/pawelmalak/flame.git synced 2025-07-18 19:19:36 +02:00

Added auth middleware. Added access control to apps

This commit is contained in:
Paweł Malak 2021-11-11 16:01:56 +01:00
parent d1c61bb393
commit e3f167921c
16 changed files with 92 additions and 9 deletions

25
middleware/auth.js Normal file
View file

@ -0,0 +1,25 @@
const jwt = require('jsonwebtoken');
const auth = (req, res, next) => {
const authHeader = req.header('Authorization');
let token;
let tokenIsValid = false;
if (authHeader && authHeader.startsWith('Bearer ')) {
token = authHeader.split(' ')[1];
}
if (token) {
try {
jwt.verify(token, process.env.SECRET);
} finally {
tokenIsValid = true;
}
}
req.isAuthenticated = tokenIsValid;
next();
};
module.exports = auth;