Skip to content

Commit

Permalink
chore: minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Franqsanz committed May 20, 2024
1 parent b82e461 commit 0b89d0c
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions src/hooks/useAccountActions.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import { useNavigate } from 'react-router-dom';
// import { useNavigate } from 'react-router-dom';
import {
// getAuth,
signOut,
reauthenticateWithCredential,
GoogleAuthProvider,
// signInWithCredential,
} from 'firebase/auth';

import { logIn } from '@services/auth/config';
import { useAuth } from '@contexts/AuthContext';
import { useDeleteAccount } from '@hooks/querys';
// import { useDeleteAccount } from '@hooks/queries';

export function useAccountActions() {
const navigate = useNavigate();
// const navigate = useNavigate();
const { currentUser } = useAuth();
const uid = currentUser?.uid;
const { mutate } = useDeleteAccount();
// const uid = currentUser?.uid;
// const { mutate } = useDeleteAccount();
// const auth = getAuth();

async function logOut() {
try {
Expand All @@ -23,24 +26,28 @@ export function useAccountActions() {
console.error('Error al cerrar sesión:', error);
}
}
// const token = await currentUser?.getIdToken();
// const accessToken = await currentUser?.getIdToken(true);
// const credential = GoogleAuthProvider.credential(token, accessToken);
// await reauthenticateWithCredential(currentUser, credential);

async function deleteAccount() {
try {
if (currentUser) {
// const idToken = await currentUser?.;
// const credential = GoogleAuthProvider.credential(idToken);
// await reauthenticateWithCredential(currentUser, credential);

await mutate(uid); // Elimina la cuenta y sus libros de la base de datos
await currentUser?.delete(); // Elimina la cuenta de Firebase
await signOut(logIn);
await window.localStorage.removeItem('app_tk');
await navigate('/', { replace: true });
const idToken = await currentUser?.getIdToken();
const credential = GoogleAuthProvider.credential(idToken);
await reauthenticateWithCredential(currentUser, credential);
await currentUser?.delete();
}
} catch (error) {
console.error('Error al borrar la cuenta:', error);
}
}
// await mutate(uid); // Elimina la cuenta y sus libros de la base de datos
// await currentUser?.delete(); // Elimina la cuenta de Firebase
// await signOut(logIn);
// await window.localStorage.removeItem('app_tk');
// await navigate('/', { replace: true });

return { logOut, deleteAccount };
}

0 comments on commit 0b89d0c

Please sign in to comment.