From 1f3b0ae54a25d691219b70ec32558b0c47d2ddc6 Mon Sep 17 00:00:00 2001 From: CATTOLATION <123876918+CATTOLATION@users.noreply.github.com> Date: Mon, 17 Jul 2023 12:30:34 +0800 Subject: [PATCH] feat: user logout --- components/dashboard/TheHeader.vue | 7 +++++++ server/trpc/routers/auth/email.ts | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/components/dashboard/TheHeader.vue b/components/dashboard/TheHeader.vue index 8f0f33f..81b2130 100644 --- a/components/dashboard/TheHeader.vue +++ b/components/dashboard/TheHeader.vue @@ -6,15 +6,22 @@ const props = defineProps<{ name: string | null }>() const config = useRuntimeConfig() +const { $client } = useNuxtApp() const menuVisible = ref(false) const menu = ref() const items = ref([ { label: 'Logout', + command: logout, }, ]) +async function logout() { + await $client.auth.email.logout.mutate() + navigateTo('/login') +} + function toggle(event: any) { menu.value.toggle(event) } diff --git a/server/trpc/routers/auth/email.ts b/server/trpc/routers/auth/email.ts index 8ed0d1b..03cfe17 100644 --- a/server/trpc/routers/auth/email.ts +++ b/server/trpc/routers/auth/email.ts @@ -58,6 +58,11 @@ export const emailSessionRouter = router({ }) return email }), + logout: publicProcedure + .mutation(async ({ ctx }) => { + await ctx.session.clear() + return true + }), verifyOtp: publicProcedure .input( z.object({