Skip to content

Commit

Permalink
Merge pull request #10 from fga-eps-mds/fix/fix-delete-account
Browse files Browse the repository at this point in the history
fix: delete account
  • Loading branch information
Matheusafonsouza authored Dec 9, 2024
2 parents f2c54b6 + 0b1cce3 commit f31a2e9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
12 changes: 12 additions & 0 deletions src/hooks/useAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type AuthContextType = {
recoverPassword: (email: string) => Promise<boolean>;
changePassword: (password: string, mailToken: string) => Promise<boolean>;
getProfile: () => Promise<User>;
deleteProfile: () => Promise<boolean>;
};

const AuthContext = createContext({} as AuthContextType);
Expand All @@ -50,6 +51,7 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
recoverPassword: authRecoverPassword,
changePassword: authChangePassword,
getProfile: authGetProfile,
deleteProfile: authDeleteProfile,
} = useApi();

const localToken =
Expand Down Expand Up @@ -149,6 +151,15 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
})
return false;
}

async function deleteProfile(): Promise<boolean> {
await authDeleteProfile(token);
toaster.create({
title: 'Perfil deletado com sucesso!',
type: 'success',
})
return true;
}

function signOut(): void {
typeof window !== 'undefined'
Expand All @@ -169,6 +180,7 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
recoverPassword,
changePassword,
getProfile,
deleteProfile,
}}
>
{children}
Expand Down
7 changes: 2 additions & 5 deletions src/pages/Profile/DeleteProfileDialog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down

0 comments on commit f31a2e9

Please sign in to comment.