diff --git a/src/api/auth.ts b/src/api/auth.ts index c5a60f59..1031eb31 100644 --- a/src/api/auth.ts +++ b/src/api/auth.ts @@ -1,5 +1,5 @@ import { Axios } from './axios'; -import { LOGIN_URL } from './constants'; +import { LOGIN_URL, LOGOUT_URL } from './constants'; export const loginIn = (username: string, password: string) => { const credentials = btoa(`${username}:${password}`); @@ -10,3 +10,7 @@ export const loginIn = (username: string, password: string) => { }, }); }; + +export const logOut = () => { + return Axios().get(LOGOUT_URL); +} diff --git a/src/api/constants.ts b/src/api/constants.ts index 48226392..51d601e6 100644 --- a/src/api/constants.ts +++ b/src/api/constants.ts @@ -54,6 +54,7 @@ export const ROLE_URL = (roleName: string) => `${ROLES_LIST_URL}/${roleName}`; // USERS LOGIN export const LOGIN_URL = `${API_V1}/o/login?redirect=${window.location.origin}`; +export const LOGOUT_URL = `${API_V1}/o/logout?redirect=${window.location.origin}`; // LLM queries export const LLM_QUERY_URL = `${API_V1}/llm`; diff --git a/src/utils/index.ts b/src/utils/index.ts index e43940f4..e8826d2a 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -3,6 +3,7 @@ import { useMemo } from 'react'; import { useLocation } from 'react-router-dom'; import Cookies from 'js-cookie'; import _ from 'lodash'; +import { logOut } from '@/api/auth'; export const baseURL = import.meta.env.VITE_PARSEABLE_URL ?? '/'; @@ -62,10 +63,15 @@ export const generateQueryParam = (obj: object) => { return `?q=${endcodedBase64}`; }; -export const signOutHandler = () => { - Cookies.remove('session'); - Cookies.remove('username'); - window.location.href = `${baseURL}api/v1/o/logout?redirect=${window.location.origin}/login`; +export const signOutHandler = async () => { + try { + await logOut(); + Cookies.remove('session'); + Cookies.remove('username'); + window.location.href = `${window.location.origin}/login`; + } catch (e) { + console.log(e); + } }; export const generateRandomId = (length: number) =>