session managment

This commit is contained in:
Mohamad.Elsena 2025-01-02 14:35:14 +01:00
parent 9259cdd84c
commit a20bfd2101

View File

@ -10,6 +10,11 @@ function setAuthToken(token: string): void {
localStorage.setItem('auth_token', token); localStorage.setItem('auth_token', token);
} }
// A simple function to save the token
function delAuthToken(): void {
localStorage.removeItem('auth_token');
}
/** /**
* Create a new form. * Create a new form.
* @param name The name of the form. * @param name The name of the form.
@ -123,3 +128,11 @@ export async function login(username: string, password: string): Promise<void> {
const { token } = await response.json(); const { token } = await response.json();
setAuthToken(token); // Store the token in localStorage setAuthToken(token); // Store the token in localStorage
} }
export function logout() {
delAuthToken();
}
export function loggedIn() {
return localStorage.getItem('auth_token') !== null;
}