Friday 30 August 2019

Is it possible to create a rest api using jwt token for a website that needs to track if the is logged in/out?

Hi, I have a website in node.js using express, all the current pages are ejs template files, that are rendered accordingly to parameters.If the user is logged in, he can see's more options in the navbar, an can access some options, like editing or deleting posts, which are not possible if the user is not logged.Using the session approuch with express I can know if the user is logged in or not while rendering the page. I set some information in the cookies using express-session, and I can verify this information to render the content in the page or not.Recently I learned how to create a rest api using jwt token, and I was wondering if I could change my current website to an rest api, which would serve the webposts information through requests, and also perform update/deletes if the jwt token is valid and autenticated.My problem is that I don't know how I would render the pages. For example, if the user is logged I need to render the page differently, with additional buttons and actions.Using jwt token I can know if the user is authenticated in the rest-api server, but my front-end server (the one that sends the webpages) wouldn't know this information and would be unable to render it correctly.How can I have the information if the user is logged, to render my views?

Submitted August 30, 2019 at 03:41PM by eliseu_videira

No comments:

Post a Comment