mirror of
https://github.com/Nezumi-2711/react-training.git
synced 2026-09-22 20:01:59 +00:00
Create hooks and implement login pages
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import { ILogin } from '@type/common';
|
||||
|
||||
// Services
|
||||
import supabase from './supabaseService';
|
||||
|
||||
const login = async ({ email, password }: ILogin) => {
|
||||
const { data, error } = await supabase.auth.signInWithPassword({
|
||||
email,
|
||||
password,
|
||||
});
|
||||
|
||||
if (error) {
|
||||
throw new Error(error.message);
|
||||
}
|
||||
|
||||
return data;
|
||||
};
|
||||
|
||||
const getCurrentAccount = async () => {
|
||||
const { data } = await supabase.auth.getSession();
|
||||
|
||||
if (!data.session) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const { data: accountData, error } = await supabase.auth.getUser();
|
||||
|
||||
if (error) {
|
||||
throw new Error(error.message);
|
||||
}
|
||||
|
||||
return accountData.user;
|
||||
};
|
||||
|
||||
const logout = async () => {
|
||||
const { error } = await supabase.auth.signOut();
|
||||
|
||||
if (error) {
|
||||
throw new Error(error.message);
|
||||
}
|
||||
};
|
||||
|
||||
export { login, logout, getCurrentAccount };
|
||||
Reference in New Issue
Block a user