Sunday, 7 May 2017

Saving JWT in cookie or local storage (node / angular 2 website)

I know that jwt can be saved in local storage or cookies. But i couldn't find a good material online for instructions. How can i instruct server to recognize the user for future sessions.

var token = jwt.sign({usern : user.username}, app.get('superSecret'), {
       //expiresInMinutes: 1440 // expires in 24 hours
 });

 //setting a cookie (it is not working)
 res.cookie('rememberme', token, { expires: new Date(Date.now() + 900000), httpOnly: false });

  // return the information including token as JSON (this is working)
  res.json({
     success: true,
     message: 'Enjoy your token!',
     token: token
  });



via Sahin Erbay

No comments:

Post a Comment