Skip to content

Commit

Permalink
Add role to auth response
Browse files Browse the repository at this point in the history
  • Loading branch information
ebenezerdon committed Nov 10, 2018
1 parent c640045 commit 4bb821f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 7 additions & 1 deletion UI/assets/js/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ const loginUser = (e) => {
};
fetch('https://newstoremanager.herokuapp.com/api/v1/auth/login', options)
.then(res => res.json())
.then(data => console.log(data.token))
.then((data) => {
if (data.success === true) {
localStorage.setItem('accesstoken', data.token);
console.log(data.token);
console.log(data.token.role);
}
})
.catch(err => console.log(err));
};

Expand Down
5 changes: 5 additions & 0 deletions server/routes/controllers/usersController.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,13 @@ const loginUser = (req, res) => {
const token = jwt.sign(data.rows[0], secret, {
expiresIn: '24hrs',
});

return res.status(201).json({
token,
role: jwt.verify(token, secret, (error, decoded) => {
const { role } = decoded;
return role;
}),
success: true,
});
}).catch(err => (res.status(500).json(err)));
Expand Down

0 comments on commit 4bb821f

Please sign in to comment.