mirror of https://github.com/wg-easy/wg-easy
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
655 B
28 lines
655 B
export const useAuthStore = defineStore('Auth', () => {
|
|
const { data: userData, refresh: update } = useFetch('/api/session', {
|
|
method: 'get',
|
|
});
|
|
|
|
/**
|
|
* @throws if unsuccessful
|
|
*/
|
|
async function login(username: string, password: string, remember: boolean) {
|
|
await $fetch('/api/session', {
|
|
method: 'post',
|
|
body: { username, password, remember },
|
|
});
|
|
return true as const;
|
|
}
|
|
|
|
/**
|
|
* @throws if unsuccessful
|
|
*/
|
|
async function logout() {
|
|
const response = await $fetch('/api/session', {
|
|
method: 'delete',
|
|
});
|
|
return response.success;
|
|
}
|
|
|
|
return { userData, login, logout, update };
|
|
});
|
|
|