2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-17 04:25:42 +00:00

re-implement logoff

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

View File

@ -26,7 +26,7 @@ export enum ApiEndpoints {
user_email_primary = 'auth/emails/:id/primary/',
user_login = '_allauth/app/v1/auth/login',
user_login_mfa = '_allauth/app/v1/auth/2fa/authenticate',
user_logout = 'auth/logout/',
user_logout = '_allauth/app/v1/auth/session',
user_register = 'auth/registration/',
// Generic API endpoints

View File

@ -91,6 +91,7 @@ export const doBasicLogin = async (
)
.then((response) => {
if (response.status == 200 && response.data?.meta?.is_authenticated) {
setSession(response.data.meta.session_token);
setToken(response.data.meta.access_token);
result = true;
}
@ -121,11 +122,16 @@ export const doBasicLogin = async (
* @arg deleteToken: If true, delete the token from the server
*/
export const doLogout = async (navigate: NavigateFunction) => {
const { clearUserState, isLoggedIn } = useUserState.getState();
const { clearUserState, isLoggedIn, setSession } = useUserState.getState();
const { session } = useUserState.getState();
// Logout from the server session
if (isLoggedIn() || !!getCsrfCookie()) {
await api.post(apiUrl(ApiEndpoints.user_logout)).catch(() => {});
await api
.delete(apiUrl(ApiEndpoints.user_logout), {
headers: { 'X-Session-Token': session }
})
.catch(() => {});
showLoginNotification({
title: t`Logged Out`,
@ -133,6 +139,7 @@ export const doLogout = async (navigate: NavigateFunction) => {
});
}
setSession(undefined);
clearUserState();
clearCsrfCookie();
navigate('/login');