-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #132 from edinstance/main
Delete account functionality
- Loading branch information
Showing
3 changed files
with
130 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
"use client"; | ||
|
||
import { Page, PageTitle } from "@/components/Page"; | ||
import { Button } from "@/components/ui/button"; | ||
import { api } from "@/convex/_generated/api"; | ||
import { useAuthActions } from "@convex-dev/auth/react"; | ||
import { useMutation, useQuery } from "convex/react"; | ||
import { redirect, useRouter } from "next/navigation"; | ||
|
||
export default function Settings() { | ||
const { signOut } = useAuthActions(); | ||
const deleteAccount = useMutation(api.users.deleteUserById); | ||
const user = useQuery(api.users.getUserOrNull); | ||
|
||
const router = useRouter(); | ||
|
||
const handleDelete = async () => { | ||
if (confirm("Are you sure you want to delete your account?")) { | ||
if (user) { | ||
await signOut(); | ||
await deleteAccount({ userId: user._id }); | ||
|
||
router.push("/"); | ||
} | ||
} | ||
}; | ||
|
||
return ( | ||
<Page> | ||
<PageTitle>Settings</PageTitle> | ||
<div> | ||
<h1 className="pb-4 text-2xl">Delete your account</h1> | ||
<p className="text-md"> | ||
If you delete your account, all of your data will be permanently | ||
removed. This includes your game results, and your user information. | ||
Any maps you created and that were approved will not be removed but | ||
you will no longer be the creator of them. This action cannot be | ||
undone. | ||
</p> | ||
<div className="flex justify-end pt-4"> | ||
<Button variant="destructive" onClick={handleDelete}> | ||
Confirm | ||
</Button> | ||
</div> | ||
</div> | ||
</Page> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters