add helper methods for authorization to Authenticator
This commit is contained in:
parent
fc3852b3cb
commit
d2507c9770
1 changed files with 14 additions and 0 deletions
|
@ -25,6 +25,20 @@ class Authenticator {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
withUser(req, res, callback) {
|
||||||
|
this.getAuthenticatedUser(req, (user) => {
|
||||||
|
if (user) callback(user);
|
||||||
|
else res.status(401).send({ code: 'auth error', message: 'user not logged in.' });
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
withAdmin(req, res, callback) {
|
||||||
|
this.withUser(req, res, (user) => {
|
||||||
|
if (user.role === 'Admin') callback(user)
|
||||||
|
else res.status(403).send({ code: 'auth error', message: 'user is not Admin.' });
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = Authenticator;
|
module.exports = Authenticator;
|
||||||
|
|
Loading…
Reference in a new issue