Giter Site home page Giter Site logo

Comments (10)

s-o-w avatar s-o-w commented on July 22, 2024

I'm also having this error/issue. Not sure what's going on, the app behaves all the way through the authentication step(s), but when returning back to the app, prior to calling for chats, get the error reported above. Have tried in incognito/inprivate, still the same

from chat-copilot.

kill136 avatar kill136 commented on July 22, 2024

me too !

BrowserAuthError.ts:351 Uncaught (in promise) BrowserAuthError: uninitialized_public_client_application: You must call and await the initialize function before attempting to call any other MSAL API. For more visit: aka.ms/msaljs/browser-errors
at createBrowserAuthError (BrowserAuthError.ts:351:1)
at blockAPICallsBeforeInitialize (BrowserUtils.ts:136:1)
at StandardController.handleRedirectPromise (StandardController.ts:333:1)
at PublicClientApplication.handleRedirectPromise (PublicClientApplication.ts:259:1)
at index.tsx:44:1

from chat-copilot.

Riya-Chaudhary-dev avatar Riya-Chaudhary-dev commented on July 22, 2024

I'm getting the same error when I start the app!

from chat-copilot.

s-o-w avatar s-o-w commented on July 22, 2024

Little more information from the logs. I'm not sure what's going on here - not a REACT programmer so I can't really tell where it's failing, but it looks like it's not setting the token in localstorage, but then expecting to find it there. This is on localhost, testing with a properly configured frontend/backend app (I know that works, it will go through the flow, just not complete once it returns back to the client).

sk-chatbot:authHelper info: +1ms [Mon, 15 Apr 2024 13:50:13 GMT] : [] : @azure/[email protected] : Info - CacheManager:getIdToken - Returning ID token common.js:113 sk-chatbot:authHelper info: +0ms [Mon, 15 Apr 2024 13:50:13 GMT] : [] : @azure/[email protected] : Info - CacheManager:getIdToken - Returning ID token common.js:113 sk-chatbot:authHelper info: +1ms [Mon, 15 Apr 2024 13:50:13 GMT] : [] : @azure/[email protected] : Info - MsalProvider - msal:handleRedirectStart results in setting inProgress from startup to handleRedirect common.js:113 sk-chatbot:authHelper info: +0ms [Mon, 15 Apr 2024 13:50:13 GMT] : [] : @azure/[email protected] : Info - CacheManager:getIdToken - Returning ID token common.js:113 sk-chatbot:authHelper info: +0ms [Mon, 15 Apr 2024 13:50:13 GMT] : [] : @azure/[email protected] : Info - MsalProvider - msal:handleRedirectEnd results in setting inProgress from handleRedirect to none common.js:113 sk-chatbot:authHelper info: +0ms [Mon, 15 Apr 2024 13:50:13 GMT] : [] : @azure/[email protected] : Info - CacheManager:getIdToken - Returning ID token common.js:113 sk-chatbot:authHelper info: +1ms [Mon, 15 Apr 2024 13:50:13 GMT] : [] : @azure/[email protected] : Info - CacheManager:getIdToken - Returning ID token common.js:113 sk-chatbot:authHelper info: +0ms [Mon, 15 Apr 2024 13:50:13 GMT] : [] : @azure/[email protected] : Info - CacheManager:getIdToken - Returning ID token common.js:113 [2024-04-15T13:50:13.267Z] Information: Using HubProtocol 'json'. Utils.ts:191 SignalR connection established signalRHubConnection.ts:108 sk-chatbot:authHelper info: +3s [Mon, 15 Apr 2024 13:50:16 GMT] : [] : @azure/[email protected] : Info - initialize has already been called, exiting early. common.js:113 sk-chatbot:authHelper info: +3s [Mon, 15 Apr 2024 13:50:19 GMT] : [] : @azure/[email protected] : Info - initialize has already been called, exiting early. common.js:113 sk-chatbot:authHelper info: +3s [Mon, 15 Apr 2024 13:50:22 GMT] : [] : @azure/[email protected] : Info - initialize has already been called, exiting early. common.js:113

from chat-copilot.

kbrkrgz10 avatar kbrkrgz10 commented on July 22, 2024

I'm getting the same error when configuring AzureAD authentication. But if you want to work without AzureAD, you can remove the frontend and authentication configuration from appsettings.development.json. You can work with guest user.

from chat-copilot.

kbrkrgz10 avatar kbrkrgz10 commented on July 22, 2024

Hello fixed this problem with the below code in webapp\src\index.tsx file.
msalInstance.handleRedirectPromise().then((response) -> response came null so an error occurred. I added else condition and got active account.

image

Reference links:

from chat-copilot.

howard2019007 avatar howard2019007 commented on July 22, 2024

@kbrkrgz10 感谢分享解决了我的问题,以下是我修改后的源码
`import { PublicClientApplication } from '@azure/msal-browser';
import { MsalProvider } from '@azure/msal-react';
import ReactDOM from 'react-dom/client';
import { Provider as ReduxProvider } from 'react-redux';
import App from './App';
import { Constants } from './Constants';
import './index.css';
import { AuthConfig, AuthHelper } from './libs/auth/AuthHelper';
import { store } from './redux/app/store';

import React from 'react';
import { BackendServiceUrl } from './libs/services/BaseService';
import { setAuthConfig } from './redux/features/app/appSlice';

if (!localStorage.getItem('debug')) {
localStorage.setItem('debug', ${Constants.debug.root}:*);
}

let container: HTMLElement | null = null;
let root: ReactDOM.Root | undefined = undefined;
let msalInstance: PublicClientApplication | undefined;

document.addEventListener('DOMContentLoaded', () => {
if (!container) {
container = document.getElementById('root');
if (!container) {
throw new Error('Could not find root element');
}
root = ReactDOM.createRoot(container);

    renderApp();
}

});

export function renderApp() {
fetch(new URL('authConfig', BackendServiceUrl))
.then((response) => (response.ok ? (response.json() as Promise) : Promise.reject()))
.then(async (authConfig) => {
store.dispatch(setAuthConfig(authConfig));

        if (AuthHelper.isAuthAAD()) {
            if (!msalInstance) {
                msalInstance = new PublicClientApplication(AuthHelper.getMsalConfig(authConfig));
                debugger;
                await msalInstance.initialize();
                await msalInstance
                    .handleRedirectPromise()
                    .then((response) => {
                        if (response) {
                            msalInstance?.setActiveAccount(response.account);
                        } else {
                            const activeAccount = msalInstance?.getAllAccounts()[0];
                            if (activeAccount) {
                                msalInstance?.setActiveAccount(activeAccount);
                            }
                        }
                    })
                    .catch((e) => {
                        console.log('handleRedirectPromise: ', e);
                    });
            }

            // render with the MsalProvider if AAD is enabled
            // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
            root!.render(
                <React.StrictMode>
                    <ReduxProvider store={store}>
                        <MsalProvider instance={msalInstance}>
                            <App />
                        </MsalProvider>
                    </ReduxProvider>
                </React.StrictMode>,
            );
        }
    })
    .catch(() => {
        store.dispatch(setAuthConfig(undefined));
    });

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
root!.render(
    <React.StrictMode>
        <ReduxProvider store={store}>
            <App />
        </ReduxProvider>
    </React.StrictMode>,
);

}
`

from chat-copilot.

s-o-w avatar s-o-w commented on July 22, 2024

fixed it on my end using the code from @kbrkrgz10 above, thank you so much!

from chat-copilot.

maximuskh avatar maximuskh commented on July 22, 2024

I still get this error in the last code I got from main and even adding what recommended by @kbrkrgz10 does not fixed it for me

from chat-copilot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.