session managment
This commit is contained in:
parent
9259cdd84c
commit
a20bfd2101
@ -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;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user