I have two roles in my REST back-end (built with Spring):
ROLE_USER, ROLE_ADMIN
When I log in, the REST API returns a valid token. Then I set it in the local storage like this:
localStorage.setItem('currentUser', JSON.stringify({username: username, token: token}));
And when I need it I get it like this:
localStorage.getItem('currentUser');
So far so good. When I get my token how do I get the payload and the claims in it?
I want to show admin panel if you are an admin.
jwtHelper.decodeToken($scope.jwt)
See https://github.com/auth0/angular-jwt and https://github.com/auth0/angular2-jwt
an example https://github.com/auth0-blog/angularjs-jwt-authentication-tutorial/blob/8841ad5d7cb034506d2e3e6840db6202e6969b7a/frontend/home/home.js#L16
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With