How to save JWT to localStorage
NasuhGencaslan opened this issue · 0 comments
NasuhGencaslan commented
I am using Angular-satellizer extension for the login/register feature but I am stuck at number 7. Token was saved to the localStorage but when refresh the page its gone and $auth.isAuthenticated()
function returning false.
.controller('loginCtrl', function($scope, $state, $auth, jwtHelper) {
$scope.login = function() {
$auth.login($scope.user)
.then(function(response) {
var gelenToken = response.data;
var tokenPayload = jwtHelper.decodeToken(gelenToken.token);
console.log(JSON.stringify(tokenPayload)); // Output:{"sub":"1","iat":1496346513,"exp":1497556113,"data":{"role":"admin"}}
localStorage.setItem('token', JSON.stringify(tokenPayload));
$state.go('baba.manga');
})
};
})