reactjs - auth0 parseHash 无法在哈希字符串上创建属性“__enableIdPInitiatedLogin”
问题描述
我正在尝试将我的 React Web 应用程序从 auth0-js 9.6.1 升级到 9.7.3。安装新库后,我的 Slack 登录流程不再起作用,它似乎在回调中中断。
TypeError: Cannot create property '__enableIdPInitiatedLogin' on string '#access_token={token string}&token_type=Bearer&state={state string}'
我的parseHash
电话是:
this.auth0.parseHash(hash, (err, authResult) => {
if (authResult && authResult.idToken) {
AuthService.setToken(authResult.idToken); // JWT returned from Auth0;
// Redirect user to content.
const returnUrl = localStorage.getItem(Variables.RETURN_URL_KEY);
localStorage.removeItem(Variables.RETURN_URL_KEY);
returnUrl
? window.location.replace(returnUrl)
: window.location.replace("/");
} else if (err) {
console.log("Error with auth callback", err);
window.location.replace("https://foo.com"); // If auth fails, send user to home page.
}
}
这在 9.6.1 中工作正常,但在 9.7.x 中失败,我找不到任何会导致它开始失败的重大更改。有任何想法吗?
解决方案
我和你有同样的问题,所以我在 Auth0.js 库 github 页面上开了一张票。
这是我从开发人员那里得到的回复:
考虑到我们希望第一个参数是对象或回调函数,它当时是偶然工作的(在你的情况下,字符串也被忽略了)。
我们所有的文档都提到:
https://github.com/auth0/auth0.js#api
https://auth0.github.io/auth0.js/global.html#parseHash
https://auth0.com/docs/libraries/auth0js/v9#extract-the-authresult-and-get-user-info
在您的情况下,最简单的解决方法是仅删除第一个参数并仅保留 callback。当没有选项对象时,已经使用了 window.location.hash。
(强调修复我的)
我用 9.7.3 测试了this.auth.auth0.parseHash((err, result) => ...
它,它就像一个魅力。
我希望这会有所帮助!
推荐阅读
- python - 迭代长列表以生成较小的列表并附加到 csv
- python - 验证数据中缺少 Django REST 框架可写嵌套序列化程序数据
- xcode - 在 Xcode C++ 中抛出“Linker command failed with exit code 1”
- c# - 我应该使用 isDbNull 吗?在这种特殊情况下如何使用它?
- public-key-encryption - 使用 2 个公钥加密
- javascript - JavaScript 单击布尔值以选择和取消选择 svg 元素。
- javascript - 在 SAPUI5 按钮上仅按一次 firePress
- javascript - 尝试集成贝宝时的ajax冲突
- hugo - 使用布局时 Hugo 页面不呈现
- javascript - 表单验证 - html 和 javascript