Skip to content

Instantly share code, notes, and snippets.

@thebergamo
Created December 15, 2015 23:42
Show Gist options
  • Save thebergamo/f572b70fb49b25adb179 to your computer and use it in GitHub Desktop.
Save thebergamo/f572b70fb49b25adb179 to your computer and use it in GitHub Desktop.
function getToken (user) {
const secretKey = process.env.JWT || ‘stubJWT’;
return jwt.sign({ id: user._id, roles: user.roles }, secretKey, {expiresIn: ‘18h’});
}
@adrian111111111
Copy link

How do I use this...

@thebergamo
Copy link
Author

That's a good question... it's been 6 years since it's originally posted :p
So I do not remember, but it seems that based on your user it would generate a JWT for you with expiration in 18h and will give you the user roles.
That was part of blog post of mine, I would suggest you to take a look: https://medium.com/@thedon/scoping-roles-in-hapi-1f3ab86d6576

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment