微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

带有 MSAL 库 React 示例的无限循环

如何解决带有 MSAL 库 React 示例的无限循环

我正在尝试无缝登录用户,没有登录按钮,因为它将托管在 Azure 上。但以错误结束无限循环:

interaction_in_progress: Interaction is currently in progress. 
Please ensure that this interaction has been completed before calling an interactive API.  
For more visit: aka.ms/msaljs/browser-errors.

示例页面布局代码修改来自 https://github.com/AzureAD/microsoft-authentication-library-for-js 的 Typescript 示例:

export const PageLayout = (props: any) => {
    const { instance,accounts,inProgress } = useMsal();
    if(instance.getActiveAccount() == null)
    {
        console.log('account =' + instance.getActiveAccount());
        instance.loginRedirect(loginRequest);
    }
    console.log('count =' + instance.getAllAccounts().length);
    console.log('active =' + instance.getAllAccounts());
    return (
        <>
            <Navbar bg="primary" variant="dark">
                <a className="navbar-brand" href="/">MS Identity Platform</a>
                {/* <SignInSignOutButton/> */}
            </Navbar>
            <h5 className="sample-header">Welcome to the Microsoft Authentication Library For Typescript - React Quickstart</h5>
            <br/>
            <br/>
            {props.children}
        </>
    );
};

解决方法

这里解决了这个问题: https://github.com/AzureAD/microsoft-authentication-library-for-js/issues/3667

建议使用 useMsalAuthentication 钩子或 MsalAuthenticationTemplate component 实现页面加载时的自动登录。您可以使用此 sample 作为指南。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。