diff --git a/app/Authenticator.js b/app/Authenticator.js index 4a0220d..d97599a 100644 --- a/app/Authenticator.js +++ b/app/Authenticator.js @@ -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;