feat: add logout feature in dashboard

This commit is contained in:
swve 2023-12-26 22:41:38 +01:00
parent 6aa849b305
commit 259007afa5
2 changed files with 44 additions and 10 deletions

View file

@ -29,6 +29,26 @@ export async function loginAndGetToken(username: string, password: string): Prom
return response;
}
export async function logout(): Promise<any> {
// Request Config
// get origin
const HeadersConfig = new Headers({ "Content-Type": "application/x-www-form-urlencoded" });
const urlencoded = new URLSearchParams();
const requestOptions: any = {
method: "DELETE",
headers: HeadersConfig,
body: urlencoded,
redirect: "follow",
credentials: "include",
};
// fetch using await and async
const response = await fetch(`${getAPIUrl()}auth/logout`, requestOptions);
return response;
}
export async function getUserInfo(token: string): Promise<any> {
const origin = window.location.origin;
const HeadersConfig = new Headers({ Authorization: `Bearer ${token}`, Origin: origin });