diff --git a/frontend/src/lib/api.ts b/frontend/src/lib/api.ts index 99e3efe..1f0c995 100644 --- a/frontend/src/lib/api.ts +++ b/frontend/src/lib/api.ts @@ -10,6 +10,11 @@ function setAuthToken(token: string): void { localStorage.setItem('auth_token', token); } +// A simple function to save the token +function delAuthToken(): void { + localStorage.removeItem('auth_token'); +} + /** * Create a new form. * @param name The name of the form. @@ -123,3 +128,11 @@ export async function login(username: string, password: string): Promise { const { token } = await response.json(); setAuthToken(token); // Store the token in localStorage } + +export function logout() { + delAuthToken(); +} + +export function loggedIn() { + return localStorage.getItem('auth_token') !== null; +}