question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is there a way to change an object stored in a token or to re-state the token without becoming unauthenticated

See original GitHub issue

I have a sessions object for a user with the following keys: email, value, session_id, user_id and roles where roles contains a key value pair of a certain event and the user’s corresponding event {1: 'ADMIN', 2: 'ANON'} . This is store in a JWT token in a cookie.

I want to update the roles object within session to {1: 'ADMIN', 2: 'ANON', 3: 'ADMIN'} , and save it as a JWT in a cookie. However, I am having problems when I try to state the token again. I have also tried unstating the previous token and re-stating the new one but this is causing authentication problems too. What is considered best practice for this kind of behaviour?

Thanks

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
nelsoniccommented, Aug 23, 2016

@naazy this is fantastic and worth adding to the FAQ section of the Readme … https://github.com/dwyl/hapi-auth-jwt2#frequently-asked-questions-faq- 😉

1reaction
naazycommented, Aug 23, 2016

This is how we did it:

var session= request.auth.credentials;
session.roles[3]='ADMIN';
var token = JWT.sign(session, process.env.JWT_SECRET); 
reply().state('token', token, { path: '/' }).redirect('/dashboard');

Note we had to set the cookie to the path that the initial cookie was set on - otherwise we were ending up with 2 different token cookies for different paths!

Read more comments on GitHub >

github_iconTop Results From Across the Web

What Are Refresh Tokens and How to Use Them Securely
You Can Store Refresh Token In Local Storage​​ Storing tokens in browser local storage provides persistence across page refreshes and browser ...
Read more >
Replace a process level token (Windows 10) - Microsoft Learn
Describes the best practices, location, values, policy management, and security considerations for the Replace a process level token ...
Read more >
How to securely store JWT tokens. - DEV Community ‍ ‍
Now, let's explore which is the best way to store a JWT token. ... a node module that you use without knowing about...
Read more >
Can You Change the Payload of a JWT Token? - YouTube
0:00 · New! Watch ads now so you can enjoy fewer interruptions. Got it.
Read more >
How to Store Session Tokens in a Browser (and the impacts of ...
This is possible by storing it is a variable inside a closure (if it helps, think of it as roughly akin to a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found