[GH-ISSUE #926] User deletion flow is flawed: problems with UX and DX #8503

Closed
opened 2026-04-13 03:35:32 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @JosipPardon on GitHub (Dec 17, 2024).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/926

Is this suited for github?

  • Yes, this is suited for github

Current vs. Expected behavior

According to docs, recommended way of setting up user deletion feature is this:

  1. Add sendDeleteAccountVerification to betterAuth({...}) in auth.ts.
  2. When user presses delete account, call authClient.deleteUser(), which triggers execution of sendDeleteAccountVerification
  3. Inside sendDeleteAccountVerification send email with URL for account deletion, which is user expected to click: sendEmail(data.user.email, "Verify Deletion", data.url)

Problem is that this URL leads to API endpoint. When user opens it, he sees this:

{FF16826C-6081-4B67-B5B7-DE2BA1AAED69}

Users should not be expected to visit API endpoints and open pages which are actually json objects, like one above.

My recommendation is this:

  1. Rename authClient.deleteUser() to authClient.sendUserDeletionToken() because original name is misleading, but keep original functionality.
  2. Create new function authClient.deleteUser({token: string}) which sends request to same URL described above, or deletes user in some other way.

So, flow should be similar as for email OTP (described here) - we have authClient.emailOtp.sendVerificationOtp and authClient.signIn.emailOtp.

If they want, inside sendDeleteAccountVerification developers can send user email with link to page which executes authClient.deleteUser({token: string}) when opened. This is how link verification can be implemented.

What version of Better Auth are you using?

1.0.21

Originally created by @JosipPardon on GitHub (Dec 17, 2024). Original GitHub issue: https://github.com/better-auth/better-auth/issues/926 ### Is this suited for github? - [X] Yes, this is suited for github ### Current vs. Expected behavior According to [docs](https://www.better-auth.com/docs/concepts/users-accounts#delete-user), recommended way of setting up user deletion feature is this: 1. Add `sendDeleteAccountVerification` to `betterAuth({...})` in `auth.ts`. 2. When user presses _delete account_, call `authClient.deleteUser()`, which triggers execution of `sendDeleteAccountVerification` 3. Inside `sendDeleteAccountVerification` send email with URL for account deletion, which is user expected to click: `sendEmail(data.user.email, "Verify Deletion", data.url)` Problem is that this URL leads to API endpoint. When user opens it, he sees this: ![{FF16826C-6081-4B67-B5B7-DE2BA1AAED69}](https://github.com/user-attachments/assets/5afcb379-9181-4de7-be6b-1337f1898705) Users should not be expected to visit API endpoints and open pages which are actually json objects, like one above. My recommendation is this: 1. Rename `authClient.deleteUser()` to `authClient.sendUserDeletionToken()` because original name is misleading, but keep original functionality. 2. Create new function `authClient.deleteUser({token: string})` which sends request to same URL described above, or deletes user in some other way. So, flow should be similar as for email OTP (described [here](https://www.better-auth.com/docs/plugins/email-otp#send-otp)) - we have `authClient.emailOtp.sendVerificationOtp` and `authClient.signIn.emailOtp`. If they want, inside `sendDeleteAccountVerification` developers can send user email with link to page which executes `authClient.deleteUser({token: string})` when opened. This is how link verification can be implemented. ### What version of Better Auth are you using? 1.0.21
GiteaMirror added the lockedbug labels 2026-04-13 03:35:32 -05:00
Author
Owner

@daveycodez commented on GitHub (Dec 18, 2024):

Is it possible to delete users without needing email verification to do so?

<!-- gh-comment-id:2552473119 --> @daveycodez commented on GitHub (Dec 18, 2024): Is it possible to delete users without needing email verification to do so?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#8503