Skip to content

Commit

Permalink
Fix deleting account
Browse files Browse the repository at this point in the history
  • Loading branch information
chunweii committed Nov 2, 2023
1 parent dce34a7 commit b2e18f0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion frontend/src/firebase-client/useDeleteOwnAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { auth } from "./firebase_config";
import { AuthContext } from "../contexts/AuthContext";
import { useContext } from "react";
import { userApiPathAddress } from "@/gateway-address/gateway-address";
import { GithubAuthProvider, reauthenticateWithCredential, signInWithPopup } from "firebase/auth";

export const useDeleteOwnAccount = () => {
const { dispatch } = useContext(AuthContext);
Expand All @@ -10,7 +11,14 @@ export const useDeleteOwnAccount = () => {
const currentUser = auth.currentUser;
if (currentUser) {
const idToken = await currentUser.getIdToken(true);

const provider = new GithubAuthProvider();
const oAuthResult = await signInWithPopup(auth, provider);
const credential = GithubAuthProvider.credentialFromResult(oAuthResult);
if (!credential) {
throw new Error("Could not get credential");
}
await reauthenticateWithCredential(currentUser, credential);

await fetch(userApiPathAddress + currentUser.uid, {
method: "DELETE",
headers: {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/settings/_account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export default function AccountSettingsCard() {
<AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>
<AlertDialogDescription>
This action cannot be undone. This will permanently delete your account
and remove your data from our servers.
and remove your data from our servers. Please log in to GitHub again to continue.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
Expand Down

0 comments on commit b2e18f0

Please sign in to comment.