Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: delete account #10

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading