angular - Angular 7 - Auth0 - parseHash 响应为空
问题描述
Auth0 问题。
我的应用程序在浏览器刷新时注销并且用户配置文件出现问题后重新触发登录事件。我将其追踪到身份验证服务中的 parseHash :
this.auth0.parseHash({ hash: window.location.hash }, (err, authResult) => {
...
}
使用 ngrx 效果触发:
@Effect()
init$ = defer(() => {
const userData = localStorage.getItem("user");
if (userData != null && userData != 'undefined') {
let authActionObservable = of(new Login({user: JSON.parse(userData)}));
this.authService.handleAuthentication();
return authActionObservable;
}
this.authService.handleAuthentication();
});
似乎 this.auth0.parseHash 在页面刷新后为 authResult 和 err 返回 null 但在初始登录时 authResult 被正确填充。
从技术上讲,登录是成功的,我得到了令牌。我检查了整个配置、域等,一切似乎都很好。我还尝试使用 { hash: window.location.hash }。
解决方案
问题在于,包含服务令牌的内存变量的状态在每次页面刷新时都会重置。一旦我重新初始化了服务构造函数中的值,问题就消失了。
这里以 localStorage 为例说明我的意思:
constructor(public router: Router, private store: Store<State>, private http: HttpClient) {
this._idToken = localStorage.getItem("Auth0IdToken");
this._accessToken = localStorage.getItem("Auth0AccessToken");
this._expiresAt = parseInt(localStorage.getItem("Auth0ExpiresAt"));
}
推荐阅读
- javascript - 将多级响应对象可视化为 Postman 中的 Table 并列出 id
- html -
在 Android 版 Zoho Mail 应用程序上忽略标签
- woocommerce - Woocommerce 订阅 API 和 Authorize.net(信用卡支付失败(订阅续订:支付令牌丢失/无效。))
- vue.js - 如何在变量中设置动态值或连接两个变量Vue
- javascript - 如果字符串在 Javascript 中是不可变的,为什么 += 运算符会以它的方式工作?
- c++ - 如何使用 CMake 与 ntdll.lib 链接?
- data-conversion - 将 PubSubClient 主机存储到 ESP32 上的 EEPROM
- r - kableExtra 格式化表格式化科学指数
- javascript - 如何使用Javascript jquery从表单中正确传递数组中的变量
- javascript - 使用Javascript将日期转换为月份年份