feature: user sign in function in composable
parent
f12e78c706
commit
f59a1b6641
@ -1,12 +1,31 @@
|
|||||||
import { AuthError } from '@supabase/gotrue-js';
|
import { AuthError } from '@supabase/gotrue-js';
|
||||||
|
|
||||||
export const userSignOut = async (): Promise<AuthError | void> => {
|
const returnMain = (): void => {
|
||||||
const router = useRouter();
|
navigateTo('/notes');
|
||||||
|
};
|
||||||
|
|
||||||
|
const userSignOut = async (): Promise<AuthError | void> => {
|
||||||
const supabase = useSupabaseAuthClient();
|
const supabase = useSupabaseAuthClient();
|
||||||
|
|
||||||
const { error } = await supabase.auth.signOut();
|
const { error } = await supabase.auth.signOut();
|
||||||
|
|
||||||
if (error) return error;
|
if (error) return error;
|
||||||
|
|
||||||
router.push('/');
|
returnMain();
|
||||||
|
};
|
||||||
|
|
||||||
|
const userSignIn = async (
|
||||||
|
email: string,
|
||||||
|
password: string
|
||||||
|
): Promise<AuthError | void> => {
|
||||||
|
const { error } = await useSupabaseAuthClient().auth.signInWithPassword({
|
||||||
|
email: email,
|
||||||
|
password: password,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (error) return error;
|
||||||
|
|
||||||
|
returnMain();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export { userSignOut, userSignIn };
|
||||||
|
|||||||
Loading…
Reference in New Issue