Wednesday, 10 May 2017

How to use Passport & JWTs on client-end for authorization?

I'm currently creating a custom CMS for a friend's soccer team. The architecture is as follows:

On the back-end I've an API that interacts with the database (mongoDB).

On the front-end I've an express server that serves the pages using the templating engine handlebars.

Currently I've managed to authorize requests to the API using Passport and JWTs, which is fine for querying the API, on login I'm storing a JWT with permissions in the cookie storage within the user (it's static pages and not a SPA so I cannot access local/session storage).

My issue is that I am struggling how to implement authorization on the client end for access to the admin panel. Should I decode the JWT on the client-end and read the user role then serve the pages if the admin pages if the user is an admin or should I be sending every request to access the admin section of the front-end to the API for a verification check then serve the files.

Any help would be greatly appreciated, thank you.



via makory

No comments:

Post a Comment