Wednesday 30 October 2019

Send JWT and redirect to another page in a single step ?

I'm using express.js to build a website. Everytime a user logs in, I generate a JWT, which is use to authorize all further activities the user does. For this I must receive the jwt as a request header, which means the user must have access to it through the frontend, so every generated jwt (after each successful login) must be sent back to the user.The problem is, I want the user to also automatically be redirected to the home page, something which requires use of res.render or res.redirect. how can I make sure the user gets back the jwt after logging in and then also gets redirected to another pageP.S. I've tried adding the jwt token as part of the header for redirect but that has not worked, the user simple gets redirected to the home page, but I can't see the jwt arriving in the headers when I test it on postman.Also, methods like appending the jwt as a search term in the res.redirect URL are also not an option, because the Auth is not a one time thing, I need the frontend to have access to the jwt for all further requests to get authenticatedI know cookies is a solution, but I'm hoping for a something cleaner that that, because there's a chance I may be redirecting the user across two different daomains at one point, in which case I don't think cookie would be a viable solution anymoreAny help is appreciated, thanks is advance !

Submitted October 30, 2019 at 05:25PM by Bowserwolf1

No comments:

Post a Comment