Skip to content
This repository was archived by the owner on May 13, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/api/auth.ts
Original file line number Diff line number Diff line change
@@ -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}`);
Expand All @@ -10,3 +10,7 @@ export const loginIn = (username: string, password: string) => {
},
});
};

export const logOut = () => {
return Axios().get(LOGOUT_URL);
}
1 change: 1 addition & 0 deletions src/api/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
Expand Down
14 changes: 10 additions & 4 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? '/';

Expand Down Expand Up @@ -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) =>
Expand Down