Question
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started