Skip to content

Commit

Permalink
feat: add sign out
Browse files Browse the repository at this point in the history
  • Loading branch information
qin-guan committed Sep 23, 2023
1 parent bb716c1 commit 29e7bb2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
11 changes: 11 additions & 0 deletions components/app/profile/page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const graduationYear = computed(() => {
})
const dependencies = Object.keys(devDependencies)
const { mutate: userSignOutMutate } = useUserSignOutMutation()
</script>

<template>
Expand All @@ -32,6 +34,15 @@ const dependencies = Object.keys(devDependencies)
</f7ListItem>
</f7List>

<f7List inset strong>
<f7ListButton color="red" @click="userSignOutMutate()">
Sign out
</f7ListButton>
<f7ListButton color="red">
Delete and unlink my account
</f7ListButton>
</f7List>

<f7List inset strong>
<f7ListButton popup-open="#acknowledgements">
Acknowledgements
Expand Down
13 changes: 12 additions & 1 deletion composables/user.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useQuery } from '@tanstack/vue-query'
import { useMutation, useQuery, useQueryClient } from '@tanstack/vue-query'
import type { User } from '~/shared/types'

const queryKeyFactory = {
Expand All @@ -13,3 +13,14 @@ export function useUser() {
enabled: computed(() => !!firebaseCurrentUser.value), // Only run when user exists
})
}

export function useUserSignOutMutation() {
const auth = useFirebaseAuth()
const queryClient = useQueryClient()
return useMutation({
mutationFn: async () => auth?.signOut(),
onSuccess() {
queryClient.clear()
},
})
}

0 comments on commit 29e7bb2

Please # to comment.