mirror of
https://github.com/pawelmalak/flame.git
synced 2024-12-21 09:11:29 +03:00
26 lines
470 B
JavaScript
26 lines
470 B
JavaScript
const jwt = require('jsonwebtoken');
|
|
|
|
const auth = (req, res, next) => {
|
|
const authHeader = req.header('Authorization-Flame');
|
|
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;
|