feat: add logout, updateProfile, updatePassword, deleteAccount to useAuth
This commit is contained in:
@@ -40,5 +40,39 @@ export function useAuth() {
|
||||
fetched.value = false
|
||||
}
|
||||
|
||||
return { user, loading, isAuthenticated, userTier, isPaidTier, fetchUser, clearUser }
|
||||
async function logout() {
|
||||
try {
|
||||
await api.post('/auth/logout')
|
||||
} finally {
|
||||
clearUser()
|
||||
}
|
||||
}
|
||||
|
||||
async function updateProfile(data) {
|
||||
const response = await api.put('/user/profile', data)
|
||||
user.value = response.data
|
||||
}
|
||||
|
||||
async function updatePassword(data) {
|
||||
await api.put('/user/password', data)
|
||||
}
|
||||
|
||||
async function deleteAccount(password) {
|
||||
await api.delete('/user', { data: { password } })
|
||||
clearUser()
|
||||
}
|
||||
|
||||
return {
|
||||
user,
|
||||
loading,
|
||||
isAuthenticated,
|
||||
userTier,
|
||||
isPaidTier,
|
||||
fetchUser,
|
||||
clearUser,
|
||||
logout,
|
||||
updateProfile,
|
||||
updatePassword,
|
||||
deleteAccount,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user