2021-11-11 15:01:56 +00:00
|
|
|
const jwt = require('jsonwebtoken');
|
|
|
|
|
|
|
|
const auth = (req, res, next) => {
|
2021-11-19 13:06:38 +00:00
|
|
|
const authHeader = req.header('Authorization-Flame');
|
2021-11-11 15:01:56 +00:00
|
|
|
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;
|