当尝试在 Next 13 中从 @azure/msal-react 登录时,就发生了错误。当我检查错误日志时,它来自核心库 @azure/msal-react。我也尝试过登录弹出窗口,但错误仍然相同
我有代码,在我的auth.ts
export const msalConfig = {
auth: {
clientId : "afxxxxx-xxxxxx-xxxxxx",
authority : "https://login.microsoftonline.com/common/",
redirectUri : "/",
}
};
export const loginRequest = {
scope: ["User.Read"]
};
_app.ts
import { MsalProvider } from '@azure/msal-react'
import { PublicClientApplication, EventType, SilentRequest, AccountInfo } from '@azure/msal-browser'
import { msalConfig } from '@/services/auth'
import type { AppProps } from 'next/app'
import { useRouter } from 'next/router'
import { CustomNavigationClient } from '@/utils/NavigationClient'
export const msalInstance = new PublicClientApplication(msalConfig);
const accounts = msalInstance.getAllAccounts();
if (accounts.length > 0) {
msalInstance.setActiveAccount(accounts[0]);
};
msalInstance.addEventCallback((event) => {
if (event.eventType === EventType.LOGIN_SUCCESS && (event.payload as SilentRequest).account) {
const account = (event.payload as SilentRequest).account;
msalInstance.setActiveAccount(account as AccountInfo);
}
});
export default function App({ Component, pageProps }: AppProps) {
const router = useRouter();
const navigationClient = new CustomNavigationClient(router);;
msalInstance.setNavigationClient(navigationClient);
return (
<MsalProvider instance={msalInstance}>
<Component {...pageProps} />
</MsalProvider>
)
}
在我的页面中只显示登录Index.ts
const initializeSignIn = () => {
instance.loginRedirect();
};
return (
<>
<UnauthenticatedTemplate>
<center>Please sign-in to see your profile information.</center>
<button onClick={initializeSignIn}>Sign In</button>
</UnauthenticatedTemplate>
</>
)
我是否错过了配置中的某些内容,或者这只是核心库中的错误?
更新:
正如这里所讨论的git问题讨论 https://github.com/AzureAD/microsoft-authentication-library-for-js/issues/5587问题在于@azure/[电子邮件受保护] /cdn-cgi/l/email-protection它被固定在@azure/[电子邮件受保护] /cdn-cgi/l/email-protection.
您可以开始使用
"@azure/msal-browser": "^2.32.2",
"@azure/msal-react": "^1.5.2"
截至本期发布时,最新发布的版本是
"@azure/msal-browser": "2.32.2",
"@azure/msal-react": "1.5.2"
我用过微软身份验证库-for-js https://github.com/AzureAD/microsoft-authentication-library-for-js/要得到@azure/msal-浏览器, @azure/msal-react使用源代码运行我的项目。工作得很好。问题似乎是在代码发布时发生的(捆绑/缩小/谁知道等等)。
在新版本发布之前,要解决该问题,请将 npm 包更改为
"@azure/msal-browser": "2.32.1",
"@azure/msal-react": "1.5.1"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)