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:
parent
d1c61bb393
commit
e3f167921c
16 changed files with 92 additions and 9 deletions
25
middleware/auth.js
Normal file
25
middleware/auth.js
Normal 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;
|
Loading…
Add table
Add a link
Reference in a new issue