Reputation: 207
I am creating routes in node js
. I am creating routes for dashboard.
JWT token
.How will be authenticate routes for Admins on backend side?
Upvotes: 0
Views: 2231
Reputation: 1449
You can be inspired by this logic, And no further explanation can be given here. follow steps (It may help):
First) define role
field into DB mongoDB
or Mysql
(for example):
enum: ['user', 'admin']
Second) create a function checkRole(role)
for check role after signin and verify jwt, then get user
Third) create separate route for admin panel (for example):
router.route('/admin-panel').use(authController.checkRole('admin'))
Upvotes: 4
Reputation: 978
You can put your authorization flag in your JWT. When a user logs in, your server generates corresponding JWT, in which included authentication info(i.e. userId
). You can put additional authorization info in the token(i.e. auth
).
Based on the auth
field, your server can identify whether the request is sent by a general user or an admin. Of course, securing the JWT from hijacking is an another story.
Upvotes: 1