我正试图在我的React应用程序中实现msal 2。我使用msal-react样例/默认模板作为我的工作模板。我能够看到我的登录页面,并使用loginRedirect方法登录。但是在返回到我的应用程序时,我会得到以下错误。我看到有人问了一个非常相似的问题(65375241)。但看起来用户放弃了它。我已列入以下补充资料。
errorCode:"state_not_found“errorMessage:”未找到国家:缓存状态“
附加信息
{ auth: { clientId: "REDACTED" authority: "REDACTED" knownAuthorities:["Redacted, Same as authority"], redirectUri: "http://localhost:3000/AuthTest", navigateToLoginRequestUrl: false }, cache: { cacheLocation: "sessionStorage", storeAuthStateInCookie: false, }, system: { loggerOptions: { ...(logger options from sample) } }发布于 2021-01-07 19:16:31
通过查看MSAL git回购问题@azure/msal-浏览器重定向不能正常工作,我能够发现我自己的错误。
我将在这里描述我的问题,以帮助其他有同样错误的人。
这是因为我不正确地使用了addEventCallback方法。
我让它在我的代码中实现为一个简单的函数调用。但是它需要被放入一个useEffect中,并在使用它之后发出removeEventCallback方法。
我有
instance.addEventCallback((message) => {
console.log(message)
})而不是
useEffect(() => {
const callbackId = instance.addEventCallback((message) => {
console.log(message)
})
return () => {
if (callbackId) {
instance.removeEventCallback(callbackId);
}
}
}, [instance])https://stackoverflow.com/questions/65613324
复制相似问题