File dump from old repo
This commit is contained in:
23
routes/middleware/authGuard.js
Normal file
23
routes/middleware/authGuard.js
Normal file
@@ -0,0 +1,23 @@
|
||||
// Repository
|
||||
const UserRepository = require('../../repositories/user-repository');
|
||||
const Users = new UserRepository();
|
||||
|
||||
// AUTHGUARD
|
||||
const authGuard = (permissions) => {
|
||||
return async (req, res, next) => {
|
||||
|
||||
// Get token from headers
|
||||
let api_token = req.headers['auracle_key'];
|
||||
|
||||
// Uses repo to validate the associated perms with the token
|
||||
Users.checkAPITokenPerms(api_token, permissions)
|
||||
.then(() => {
|
||||
next();
|
||||
})
|
||||
.catch(err => {
|
||||
res.status(err.code).send(JSON.stringify(err));
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = authGuard;
|
||||
Reference in New Issue
Block a user