From ad1a3e78d22981371840b1a44dde2b8ecc26e8d3 Mon Sep 17 00:00:00 2001 From: Noah Spannbauer Date: Sun, 19 Jan 2025 16:05:23 -0600 Subject: [PATCH] Refactoring --- app/src/hooks/auth/authProvider.tsx | 42 +++++++---------------------- 1 file changed, 9 insertions(+), 33 deletions(-) diff --git a/app/src/hooks/auth/authProvider.tsx b/app/src/hooks/auth/authProvider.tsx index 9d708af..8e1676c 100644 --- a/app/src/hooks/auth/authProvider.tsx +++ b/app/src/hooks/auth/authProvider.tsx @@ -10,45 +10,21 @@ interface AuthProviderProps { export const AuthProvider = ({ children }: AuthProviderProps ) => { const msalInstance = new PublicClientApplication(msalConfig); - msalInstance.initialize().then(() => { - msalInstance.handleRedirectPromise().then(handleResponse).catch((error) => { - console.error(error); - }) - }).catch((error) => { - console.log('handleRedirectPromise: ' + error) - }) - - const handleResponse = () => { - if (!msalInstance.getActiveAccount() && msalInstance.getAllAccounts().length > 0) { + // Default to using the first account if no account is active on page load + if (!msalInstance.getActiveAccount() && msalInstance.getAllAccounts().length > 0) { // Account selection logic is app dependent. Adjust as needed for different use cases. msalInstance.setActiveAccount(msalInstance.getAllAccounts()[0]); - } - - msalInstance.addEventCallback((event) => { - const authenticationResult = event.payload as AuthenticationResult; - const account = authenticationResult?.account; - - if (event.eventType === EventType.LOGIN_SUCCESS && account) { - msalInstance.setActiveAccount(account); - } - }); } - // Default to using the first account if no account is active on page load - // if (!msalInstance.getActiveAccount() && msalInstance.getAllAccounts().length > 0) { - // // Account selection logic is app dependent. Adjust as needed for different use cases. - // msalInstance.setActiveAccount(msalInstance.getAllAccounts()[0]); - // } - // Listen for sign-in event and set active account - // msalInstance.addEventCallback((event) => { - // const authenticationResult = event.payload as AuthenticationResult; - // const account = authenticationResult?.account; + msalInstance.addEventCallback((event) => { + const authenticationResult = event.payload as AuthenticationResult; + const account = authenticationResult?.account; - // if (event.eventType === EventType.LOGIN_SUCCESS && account) { - // msalInstance.setActiveAccount(account); - // } - // }); + if (event.eventType === EventType.LOGIN_SUCCESS && account) { + msalInstance.setActiveAccount(account); + } + }); return {children}