From 0b1cce3c57b5b7370661e36cf7e3e59eb7629c39 Mon Sep 17 00:00:00 2001 From: Matheusafonsouza Date: Mon, 9 Dec 2024 00:55:41 -0300 Subject: [PATCH] fix: delete account --- src/hooks/useAuth.tsx | 12 ++++++++++++ src/pages/Profile/DeleteProfileDialog/index.tsx | 7 ++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/hooks/useAuth.tsx b/src/hooks/useAuth.tsx index a7d9887..61571d9 100644 --- a/src/hooks/useAuth.tsx +++ b/src/hooks/useAuth.tsx @@ -38,6 +38,7 @@ type AuthContextType = { recoverPassword: (email: string) => Promise; changePassword: (password: string, mailToken: string) => Promise; getProfile: () => Promise; + deleteProfile: () => Promise; }; const AuthContext = createContext({} as AuthContextType); @@ -50,6 +51,7 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => { recoverPassword: authRecoverPassword, changePassword: authChangePassword, getProfile: authGetProfile, + deleteProfile: authDeleteProfile, } = useApi(); const localToken = @@ -149,6 +151,15 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => { }) return false; } + + async function deleteProfile(): Promise { + await authDeleteProfile(token); + toaster.create({ + title: 'Perfil deletado com sucesso!', + type: 'success', + }) + return true; + } function signOut(): void { typeof window !== 'undefined' @@ -169,6 +180,7 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => { recoverPassword, changePassword, getProfile, + deleteProfile, }} > {children} diff --git a/src/pages/Profile/DeleteProfileDialog/index.tsx b/src/pages/Profile/DeleteProfileDialog/index.tsx index 528e4f2..0dc9bc7 100644 --- a/src/pages/Profile/DeleteProfileDialog/index.tsx +++ b/src/pages/Profile/DeleteProfileDialog/index.tsx @@ -11,18 +11,15 @@ import { DialogCloseTrigger, } from "../../../components/ui/dialog" import { Button } from "../../../components/ui/button" -import useApi from "../../../hooks/useApi" import { useAuth } from "../../../hooks/useAuth" import { useNavigate } from "react-router" const DeleteProfileDialog = () => { const navigate = useNavigate(); - const { deleteProfile } = useApi(); - const { signOut, getProfile } = useAuth(); + const { signOut, deleteProfile } = useAuth(); const handleDelete = async () => { - const profile = await getProfile(); - await deleteProfile(profile.id); + await deleteProfile(); signOut(); navigate('/login'); }