Home / Function/ DeleteAccountButton() — supabase Function Reference

DeleteAccountButton() — supabase Function Reference

Architecture documentation for the DeleteAccountButton() function in DeleteAccountButton.tsx from the supabase codebase.

Entity Profile

Dependency Diagram

graph TD
  2e4966ba_469e_4447_510a_d4b18a16799d["DeleteAccountButton()"]
  018fd6e2_8e31_9149_85fa_bb17d243d91e["setDeletionRequestFlag()"]
  2e4966ba_469e_4447_510a_d4b18a16799d -->|calls| 018fd6e2_8e31_9149_85fa_bb17d243d91e
  eeab8161_a8e8_32a0_3af7_abc8c3f8c9a7["hasActiveDeletionRequest()"]
  2e4966ba_469e_4447_510a_d4b18a16799d -->|calls| eeab8161_a8e8_32a0_3af7_abc8c3f8c9a7
  style 2e4966ba_469e_4447_510a_d4b18a16799d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

apps/studio/components/interfaces/Account/Preferences/DeleteAccountButton.tsx lines 53–203

export const DeleteAccountButton = () => {
  const { profile } = useProfile()
  const [isOpen, setIsOpen] = useState(false)
  const { data: organizations, isSuccess } = useOrganizationsQuery()

  const accountEmail = profile?.primary_email
  const FormSchema = z.object({ account: z.string() })
  const form = useForm<z.infer<typeof FormSchema>>({
    mode: 'onBlur',
    reValidateMode: 'onBlur',
    resolver: zodResolver(FormSchema),
    defaultValues: { account: '' },
  })
  const { account } = form.watch()

  const { mutate: submitSupportTicket, isPending } = useSendSupportTicketMutation({
    onSuccess: () => {
      setIsOpen(false)
      setDeletionRequestFlag()
      toast.success(
        'Successfully submitted account deletion request - we will reach out to you via email once the request is completed!',
        { duration: 8000 }
      )
    },
    onError: (error) => {
      toast.error(`Failed to submit account deletion request: ${error}`)
    },
  })

  const onConfirmDelete = async () => {
    if (!accountEmail) return console.error('Account information is required')

    if (hasActiveDeletionRequest()) {
      return toast.error('You have already submitted a deletion request within the last 30 days.')
    }

    const payload = {
      subject: 'Account Deletion Request',
      message: 'I want to delete my account.',
      category: SupportCategories.ACCOUNT_DELETION,
      severity: 'Low',
      allowSupportAccess: false,
      verified: true,
      projectRef: NO_PROJECT_MARKER,
    }

    submitSupportTicket(payload)
  }

  useEffect(() => {
    if (isOpen && form !== undefined) form.reset({ account: '' })
  }, [form, isOpen])

  return (
    <Dialog open={isOpen} onOpenChange={setIsOpen}>
      <DialogTrigger asChild>
        <Button type="danger" loading={!accountEmail}>
          Request to delete account
        </Button>
      </DialogTrigger>
      <DialogContent className="!w-[500px]">
        <DialogHeader>
          {(organizations ?? []).length > 0 ? (
            <>
              <DialogTitle>Leave all organizations before requesting account deletion</DialogTitle>
              <DialogDescription>
                This will allow us to process your account deletion request faster
              </DialogDescription>
            </>
          ) : (
            <>
              <DialogTitle>Are you sure you want to delete your account?</DialogTitle>
              <DialogDescription>
                Deleting your account is permanent and{' '}
                <span className="text-foreground">cannot</span> be undone
              </DialogDescription>
            </>
          )}
        </DialogHeader>

        <Separator />

        {isSuccess && (
          <>
            {organizations.length > 0 ? (
              <>
                <DialogSection>
                  <span className="text-sm text-foreground flex flex-col gap-y-2">
                    Before submitting an account deletion request, please ensure that your account
                    is not part of any organization. This can be done by leaving or deleting the
                    organizations that you are a part of.
                  </span>
                </DialogSection>
                <DialogFooter>
                  <Button block type="primary" size="medium" onClick={() => setIsOpen(false)}>
                    Understood
                  </Button>
                </DialogFooter>
              </>
            ) : (
              <Form_Shadcn_ {...form}>
                <form
                  id="account-deletion-request"
                  onSubmit={form.handleSubmit(() => onConfirmDelete())}
                >
                  <DialogSection>
                    <FormField_Shadcn_
                      name="account"
                      control={form.control}
                      render={({ field }) => (
                        <FormItem_Shadcn_>
                          <FormLabel_Shadcn_>
                            Please type{' '}
                            <span className="font-bold">{profile?.primary_email ?? ''}</span> to
                            confirm
                          </FormLabel_Shadcn_>
                          <FormControl_Shadcn_>
                            <Input_Shadcn_
                              autoFocus
                              {...field}
                              autoComplete="off"
                              disabled={isPending}
                              placeholder="Enter the account above"
                            />
                          </FormControl_Shadcn_>
                        </FormItem_Shadcn_>
                      )}
                    />
                  </DialogSection>

                  <DialogFooter>
                    <Button
                      block
                      size="small"
                      type="danger"
                      htmlType="submit"
                      loading={isPending}
                      disabled={account !== accountEmail || isPending}
                    >
                      Submit request for account deletion
                    </Button>
                  </DialogFooter>
                </form>
              </Form_Shadcn_>
            )}
          </>
        )}
      </DialogContent>
    </Dialog>
  )
}

Subdomains

Frequently Asked Questions

What does DeleteAccountButton() do?
DeleteAccountButton() is a function in the supabase codebase.
What does DeleteAccountButton() call?
DeleteAccountButton() calls 2 function(s): hasActiveDeletionRequest, setDeletionRequestFlag.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free