2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-17 12:35:46 +00:00

stop failure message from appearing when in MFA flow

This commit is contained in:
Matthias Mair
2024-12-26 18:10:52 +01:00
parent d701182d52
commit 7bfdc86799
3 changed files with 12 additions and 6 deletions

View File

@ -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`,

View File

@ -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;
};
/**

View File

@ -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<UserStateProps>((set, get) => ({
setApiDefaults();
},
session: undefined,
setSession: (newSession: string) => {
setSession: (newSession: string | undefined) => {
set({ session: newSession });
},
userId: () => {