-
Notifications
You must be signed in to change notification settings - Fork 14
Delete user account #64
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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,189 @@ | ||
| import { useState } from "react"; | ||
| import { AlertDestructive } from "@/components/AlertDestructive"; | ||
| import { Button } from "@/components/ui/button"; | ||
| import { Input } from "@/components/ui/input"; | ||
| import { Label } from "@/components/ui/label"; | ||
| import { | ||
| AlertDialog, | ||
| AlertDialogCancel, | ||
| AlertDialogContent, | ||
| AlertDialogDescription, | ||
| AlertDialogFooter, | ||
| AlertDialogHeader, | ||
| AlertDialogTitle | ||
| } from "@/components/ui/alert-dialog"; | ||
| import { generateSecureSecret, hashSecret, useOpenSecret } from "@opensecret/react"; | ||
| import { getBillingService } from "@/billing/billingService"; | ||
| import { Loader2 } from "lucide-react"; | ||
|
|
||
| interface DeleteAccountDialogProps { | ||
| open: boolean; | ||
| onOpenChange: (open: boolean) => void; | ||
| } | ||
|
|
||
| export function DeleteAccountDialog({ open, onOpenChange }: DeleteAccountDialogProps) { | ||
| const os = useOpenSecret(); | ||
| const [step, setStep] = useState<"request" | "confirm">("request"); | ||
| const [uuid, setUuid] = useState(""); | ||
| const [secret, setSecret] = useState(""); | ||
| const [isLoading, setIsLoading] = useState(false); | ||
| const [error, setError] = useState<string | null>(null); | ||
| const [confirmText, setConfirmText] = useState(""); | ||
|
|
||
| // Initial request for account deletion | ||
| const handleRequestDeletion = async () => { | ||
| if (confirmText !== "DELETE") { | ||
|
AnthonyRonning marked this conversation as resolved.
|
||
| setError("Please type DELETE to confirm"); | ||
| return; | ||
| } | ||
|
|
||
| setIsLoading(true); | ||
| setError(null); | ||
|
|
||
| try { | ||
| // Generate a random secret and store it | ||
| const generatedSecret = generateSecureSecret(); | ||
| const hashedSecret = await hashSecret(generatedSecret); | ||
|
|
||
| // Request account deletion | ||
| await os.requestAccountDeletion(hashedSecret); | ||
|
|
||
| // Store the secret and move to confirmation step | ||
| setSecret(generatedSecret); | ||
| setStep("confirm"); | ||
| } catch (err) { | ||
| setError("Failed to request account deletion. Please try again."); | ||
| console.error(err); | ||
| } finally { | ||
| setIsLoading(false); | ||
| } | ||
| }; | ||
|
|
||
| // Confirm deletion with the UUID from email | ||
| const handleConfirmDeletion = async () => { | ||
| setIsLoading(true); | ||
| setError(null); | ||
|
|
||
| try { | ||
| // Confirm account deletion with UUID and secret | ||
| await os.confirmAccountDeletion(uuid, secret); | ||
|
|
||
| // Clear all tokens and storage | ||
| try { | ||
| // Clear billing token | ||
| getBillingService().clearToken(); | ||
| } catch (error) { | ||
| console.error("Error clearing billing token:", error); | ||
| // Fallback to direct session storage removal | ||
| sessionStorage.removeItem("maple_billing_token"); | ||
| } | ||
|
|
||
| // Sign out | ||
| await os.signOut(); | ||
|
|
||
| // Force page refresh to go to logged out state | ||
| window.location.href = "/"; | ||
| } catch (err) { | ||
| setError("Failed to confirm account deletion. Please verify your code and try again."); | ||
| console.error(err); | ||
| setIsLoading(false); | ||
|
AnthonyRonning marked this conversation as resolved.
|
||
| } | ||
| }; | ||
|
AnthonyRonning marked this conversation as resolved.
|
||
|
|
||
| const handleCancel = () => { | ||
| setStep("request"); | ||
| setError(null); | ||
| setConfirmText(""); | ||
| setUuid(""); | ||
| onOpenChange(false); | ||
| }; | ||
|
|
||
| return ( | ||
| <AlertDialog open={open} onOpenChange={onOpenChange}> | ||
| <AlertDialogContent className="max-w-md"> | ||
| <AlertDialogHeader> | ||
| <AlertDialogTitle> | ||
| {step === "request" ? "Delete Account" : "Confirm Account Deletion"} | ||
| </AlertDialogTitle> | ||
| <AlertDialogDescription> | ||
| {step === "request" | ||
| ? "This action cannot be undone. This will permanently delete your account and all your data." | ||
| : "Please check your email for a confirmation code and enter it below."} | ||
| </AlertDialogDescription> | ||
| </AlertDialogHeader> | ||
|
|
||
| <div className="mt-4 space-y-4"> | ||
| {step === "request" && ( | ||
| <div className="space-y-4"> | ||
| <div className="rounded-md bg-destructive/10 p-3 text-sm text-destructive"> | ||
| <p> | ||
| Warning: This will permanently delete your account and all associated data. You | ||
| will lose access to any paid features, chat history, and settings. | ||
| </p> | ||
| </div> | ||
| <div className="space-y-2"> | ||
| <Label htmlFor="confirm-text">Type DELETE to confirm</Label> | ||
| <Input | ||
| id="confirm-text" | ||
| value={confirmText} | ||
| onChange={(e) => setConfirmText(e.target.value)} | ||
| className="w-full" | ||
| /> | ||
| </div> | ||
| </div> | ||
| )} | ||
|
|
||
| {step === "confirm" && ( | ||
| <div className="space-y-2"> | ||
| <Label htmlFor="confirmation-code">Confirmation Code</Label> | ||
| <Input | ||
| id="confirmation-code" | ||
| value={uuid} | ||
| onChange={(e) => setUuid(e.target.value)} | ||
| placeholder="Enter code from email" | ||
| className="w-full" | ||
|
AnthonyRonning marked this conversation as resolved.
|
||
| /> | ||
| </div> | ||
| )} | ||
|
|
||
| {error && <AlertDestructive title="Error" description={error} />} | ||
| </div> | ||
|
|
||
| <AlertDialogFooter className="mt-4"> | ||
| <AlertDialogCancel onClick={handleCancel}>Cancel</AlertDialogCancel> | ||
| {step === "request" ? ( | ||
| <Button | ||
| variant="destructive" | ||
| onClick={handleRequestDeletion} | ||
| disabled={isLoading || confirmText !== "DELETE"} | ||
| > | ||
| {isLoading ? ( | ||
| <> | ||
| <Loader2 className="mr-2 h-4 w-4 animate-spin" /> | ||
| Processing... | ||
| </> | ||
| ) : ( | ||
| "Delete Account" | ||
| )} | ||
| </Button> | ||
| ) : ( | ||
| <Button | ||
| variant="destructive" | ||
| onClick={handleConfirmDeletion} | ||
| disabled={isLoading || !uuid} | ||
| > | ||
| {isLoading ? ( | ||
| <> | ||
| <Loader2 className="mr-2 h-4 w-4 animate-spin" /> | ||
| Processing... | ||
| </> | ||
| ) : ( | ||
| "Confirm Deletion" | ||
| )} | ||
| </Button> | ||
| )} | ||
| </AlertDialogFooter> | ||
| </AlertDialogContent> | ||
| </AlertDialog> | ||
| ); | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.