Tokens can also have a admin property. When admin is defined its included in the jwt token.

This commit is contained in:
2019-07-25 00:13:28 +02:00
parent 8a5ab204e1
commit 12afbf6364
3 changed files with 32 additions and 24 deletions

View File

@@ -21,9 +21,9 @@ function loginController(req, res) {
userSecurity.login(user, password)
.then(() => userRepository.checkAdmin(user))
.then((checkAdmin) => {
const token = new Token(user).toString(secret);
const admin_state = checkAdmin === 1 ? true : false;
res.send({ success: true, token, admin: admin_state });
const isAdmin = checkAdmin === 1 ? true : false;
const token = new Token(user, isAdmin).toString(secret);
res.send({ success: true, token });
})
.catch((error) => {
res.status(401).send({ success: false, error: error.message });

View File

@@ -21,10 +21,10 @@ function registerController(req, res) {
userSecurity.createNewUser(user, password)
.then(() => userRepository.checkAdmin(user))
.then((checkAdmin) => {
const token = new Token(user).toString(secret);
const admin_state = checkAdmin === 1 ? true : false;
const isAdmin = checkAdmin === 1 ? true : false;
const token = new Token(user, isAdmin).toString(secret);
res.send({
success: true, message: 'Welcome to Seasoned!', token, admin: admin_state,
success: true, message: 'Welcome to Seasoned!', token
});
})
.catch((error) => {