mirror of
https://github.com/Nezumi-2711/react-training.git
synced 2026-09-22 20:01:59 +00:00
Add edit information account page
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
import { ILogin } from '@type/common';
|
||||
import { UserAttributes } from '@supabase/supabase-js';
|
||||
|
||||
// Services
|
||||
import supabase from './supabaseService';
|
||||
|
||||
// Types
|
||||
import { IAccount } from '@type/account';
|
||||
|
||||
const login = async ({ email, password }: ILogin) => {
|
||||
const { data, error } = await supabase.auth.signInWithPassword({
|
||||
email,
|
||||
@@ -40,4 +44,25 @@ const logout = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
export { login, logout, getCurrentAccount };
|
||||
const updateAccount = async ({ fullName, password }: IAccount) => {
|
||||
let accountUpdate: UserAttributes | null = null;
|
||||
|
||||
if (password) {
|
||||
accountUpdate = { password };
|
||||
}
|
||||
|
||||
if (fullName) {
|
||||
accountUpdate = { data: { fullName } };
|
||||
}
|
||||
|
||||
const { data, error } = await supabase.auth.updateUser(accountUpdate!);
|
||||
|
||||
if (error) {
|
||||
console.error(error.message);
|
||||
throw new Error(error.message);
|
||||
}
|
||||
|
||||
return data;
|
||||
};
|
||||
|
||||
export { login, logout, getCurrentAccount, updateAccount };
|
||||
|
||||
Reference in New Issue
Block a user