diff --git a/src/frontend/src/components/forms/AuthenticationForm.tsx b/src/frontend/src/components/forms/AuthenticationForm.tsx index 4a144986ce..71b99f6573 100644 --- a/src/frontend/src/components/forms/AuthenticationForm.tsx +++ b/src/frontend/src/components/forms/AuthenticationForm.tsx @@ -50,7 +50,7 @@ export function AuthenticationForm() { classicForm.values.password, navigate ) - .then(() => { + .then((success) => { setIsLoggingIn(false); if (isLoggedIn()) { @@ -59,6 +59,8 @@ export function AuthenticationForm() { message: t`Logged in successfully` }); followRedirect(navigate, location?.state); + } else if (success) { + // MFA login } else { showLoginNotification({ title: t`Login failed`, diff --git a/src/frontend/src/functions/auth.tsx b/src/frontend/src/functions/auth.tsx index ad28f0919e..60ce2d7949 100644 --- a/src/frontend/src/functions/auth.tsx +++ b/src/frontend/src/functions/auth.tsx @@ -75,7 +75,8 @@ export const doBasicLogin = async ( const login_url = apiUrl(ApiEndpoints.user_login); - let result = false; + let loginDone = false; + let success = false; // Attempt login with await api @@ -93,7 +94,8 @@ export const doBasicLogin = async ( if (response.status == 200 && response.data?.meta?.is_authenticated) { setSession(response.data.meta.session_token); setToken(response.data.meta.access_token); - result = true; + loginDone = true; + success = true; } }) .catch((err) => { @@ -103,17 +105,19 @@ export const doBasicLogin = async ( ); if (mfa_flow && mfa_flow.is_pending == true) { setSession(err.response.data.meta.session_token); + success = true; navigate('/mfa'); } } }); - if (result) { + if (loginDone) { await fetchUserState(); fetchGlobalStates(); } else { clearUserState(); } + return success; }; /** diff --git a/src/frontend/src/states/UserState.tsx b/src/frontend/src/states/UserState.tsx index c5f7094286..965de1f6f5 100644 --- a/src/frontend/src/states/UserState.tsx +++ b/src/frontend/src/states/UserState.tsx @@ -17,7 +17,7 @@ export interface UserStateProps { setToken: (newToken: string) => void; clearToken: () => void; session: string | undefined; - setSession: (newSession: string) => void; + setSession: (newSession: string | undefined) => void; fetchUserToken: () => void; fetchUserState: () => void; clearUserState: () => void; @@ -54,7 +54,7 @@ export const useUserState = create((set, get) => ({ setApiDefaults(); }, session: undefined, - setSession: (newSession: string) => { + setSession: (newSession: string | undefined) => { set({ session: newSession }); }, userId: () => {