Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am using JWT tokens on express. I have login/register API' that give users JWT tokens when they successfully login/register. When a user login/registers, they

I am using JWT tokens on express. I have login/register API' that give users JWT tokens when they successfully login/register.

When a user login/registers, they are redirected to home. How can I display the users' username on the homepage when they are redirected to home?? Here is code I am using:

//HOME API// router.get('/home', function(req, res, next) { try { var jwtString = req.cookies.Authorization.split(" "); var profile = verifyJwt(jwtString[1]); if (profile) { res.render('home'); } }

//*Creates a JWT*// function createJwt(profile) { return jwt.sign(profile, 'jwtcode', { expiresIn: '20d' }); }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

2nd Edition

1597499471, 978-1597499477

More Books

Students also viewed these Databases questions

Question

=+8.4. Show that B 8 [W] k-0 n=1m=1 A-1

Answered: 1 week ago

Question

bandi

Answered: 1 week ago

Question

Decision Making in Groups Leadership in Meetings

Answered: 1 week ago