Fixed some bugs in api and auth services, completed auth cores.
This commit is contained in:
20
api/src/middlewares/internalware.js
Normal file
20
api/src/middlewares/internalware.js
Normal file
@@ -0,0 +1,20 @@
|
||||
const interalToken = process.env.INTERNAL_API_TOKEN;
|
||||
|
||||
export function internalware(req, res, next) {
|
||||
if (req.headers['x-internal-token'] === interalToken) {
|
||||
req.internal = true; // La richiesta è interna
|
||||
return next();
|
||||
}
|
||||
return res.status(403).json({error: 'not-internal'});
|
||||
}
|
||||
|
||||
export function userOrInternal(userware) {
|
||||
return (req, res, next) => {
|
||||
if (req.headers['x-internal-token'] === interalToken) {
|
||||
req.internal = true;
|
||||
return next();
|
||||
}
|
||||
return userware(req, res, next);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user