mirror of
https://github.com/emailerfacu-spec/minix-front.git
synced 2026-04-16 15:37:32 -03:00
añadido componente para crear posts y modificado menu auth
This commit is contained in:
25
src/lib/hooks/logout.ts
Normal file
25
src/lib/hooks/logout.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { goto } from '$app/navigation';
|
||||
import { apiBase } from '@/stores/url';
|
||||
import { sesionStore } from '@/stores/usuario';
|
||||
|
||||
export async function logout(menuOpen: boolean) {
|
||||
try {
|
||||
const req = await fetch($apiBase + '/api/auth/logout', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${$sesionStore.accessToken}`
|
||||
},
|
||||
credentials: 'include'
|
||||
});
|
||||
if (req.ok) {
|
||||
sesionStore.reset();
|
||||
menuOpen = false;
|
||||
}
|
||||
} catch {
|
||||
console.log('fallo el lougout');
|
||||
} finally {
|
||||
sesionStore.reset();
|
||||
goto('/');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user