我正在尝试将我的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中失败,我找不到任何会导致它开始失败的重大更改。有任何想法吗?
我和你有同样的问题所以我开了一个ticket on the Auth0.js library github page.
这是我从开发者那里得到的回应:
它是偶然工作的(同样,在你的情况下,字符串被忽略),考虑到我们期望第一个参数要么是对象,要么是回调函数。
我们所有的文档都提到:
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
在您的情况下,最简单的解决方法是删除第一个参数并仅保留回调。当没有选项对象时,已经使用了window.location.hash。
(强调修复我的)
我用this.auth.auth0.parseHash((err, result) => ...
测试了9.7.3,它就像一个魅力。
我希望这会有所帮助!