add frontend logout
This commit is contained in:
parent
d457c766c3
commit
c15c13fd38
2 changed files with 58 additions and 0 deletions
|
|
@ -101,6 +101,20 @@ export const useAuthStore = defineStore('auth', () => {
|
|||
}
|
||||
}
|
||||
|
||||
async function logout(): Promise<void> {
|
||||
try {
|
||||
await fetch(`${API_BASE}/api/logout`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
},
|
||||
})
|
||||
} finally {
|
||||
user.value = null
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
user,
|
||||
loading,
|
||||
|
|
@ -108,5 +122,6 @@ export const useAuthStore = defineStore('auth', () => {
|
|||
isAuthenticated,
|
||||
fetchMe,
|
||||
login,
|
||||
logout,
|
||||
}
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue