From f59a1b6641019578f88029bc81d5b23672b38bb2 Mon Sep 17 00:00:00 2001 From: TZGyn Date: Sun, 12 Feb 2023 03:43:05 +0800 Subject: [PATCH] feature: user sign in function in composable --- composables/user.ts | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/composables/user.ts b/composables/user.ts index 8059932..accf629 100644 --- a/composables/user.ts +++ b/composables/user.ts @@ -1,12 +1,31 @@ import { AuthError } from '@supabase/gotrue-js'; -export const userSignOut = async (): Promise => { - const router = useRouter(); +const returnMain = (): void => { + navigateTo('/notes'); +}; + +const userSignOut = async (): Promise => { const supabase = useSupabaseAuthClient(); const { error } = await supabase.auth.signOut(); if (error) return error; - router.push('/'); + returnMain(); +}; + +const userSignIn = async ( + email: string, + password: string +): Promise => { + const { error } = await useSupabaseAuthClient().auth.signInWithPassword({ + email: email, + password: password, + }); + + if (error) return error; + + returnMain(); }; + +export { userSignOut, userSignIn };