Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/449.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 页面刷新时卫星登录JWT令牌消失_Javascript_Angularjs_Jwt_Satellizer - Fatal编程技术网

Javascript 页面刷新时卫星登录JWT令牌消失

Javascript 页面刷新时卫星登录JWT令牌消失,javascript,angularjs,jwt,satellizer,Javascript,Angularjs,Jwt,Satellizer,我正在使用登录/注册功能的扩展,但我被困在第7位 令牌已保存到localStorage,但我在刷新页面时它已消失,$auth.isAuthenticated()函数返回false 当您刷新页面时,您可能正在重置本地存储,并且您的最后一个令牌消失了 试试这个 // if the localScore is not set then initialize it if(localStorage.getItem('token') === null) { localStorage.setIt

我正在使用登录/注册功能的扩展,但我被困在第7位

令牌已保存到
localStorage
,但我在刷新页面时它已消失,
$auth.isAuthenticated()
函数返回false


当您刷新页面时,您可能正在重置本地存储,并且您的最后一个令牌消失了

试试这个

// if the localScore is not set then initialize it 
if(localStorage.getItem('token') === null) {
     localStorage.setItem('token', JSON.stringify(tokenPayload));
}
你应该试试这个:

localStorage.setItem('token',data.token)

$window.localStorage.token=JSON.stringify(data.token)

若要保存令牌,您可以在浏览器本地存储中查看令牌,除非需要,否则无需解码该令牌

它不应该在页面刷新时被删除,如果它被删除,我建议您尝试在位置上设置断点并调试哪个部分正在清除本地存储


浏览器在任何时候都不会删除任何本地存储数据,您的代码可能正在执行此操作。

卫星manuel说
解析令牌并将其保存到本地存储。解析意味着解码,对吗?我不这么认为,解析意味着提取和保存,而不是解码,你必须将编码的令牌发送到未解码的服务器。好的。我发现了这个问题。仅为
login.html
保存令牌,而不是为所有页面保存令牌。现在我需要与
index.html
$scope.isAuthenticated=function()共享令牌,并与
index.html
的状态共享此函数。哪个更好?Satellizer有自己的函数
$auth.setToken(token)
,这会为所有页面保存token。非常感谢。
// if the localScore is not set then initialize it 
if(localStorage.getItem('token') === null) {
     localStorage.setItem('token', JSON.stringify(tokenPayload));
}