本文介绍了如何将JWT保存到localStorage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我将Angular-satellizer扩展用于登录/注册功能,但卡在第7位.我无法将JWT保存到localStorage.我在chrome中检查了开发者工具,但没有令牌.

I am using Angular-satellizer extension for the login/register feature but I am stuck at number 7. I cant save JWT to localStorage. I checked the developer tools in chrome but there is no token.

.controller('loginCtrl', function($scope, $state, $auth, jwtHelper, $window) {
$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"}}

    $window.localStorage.setItem('token', JSON.stringify(tokenPayload));

    $state.go('baba.manga');
    })
};
})

推荐答案

您可以同时使用:

如果它在页面刷新时被删除,那么您需要检查是否已在某个地方重置了localStorage或某些脚本正在执行

If it's getting deleted on page refresh then you need to check if you have reset the localStorage somewhere or some script is doing it

这篇关于如何将JWT保存到localStorage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 15:43