[PR #6377] [MERGED] feat(anonymous): delete anonymous user endpoint #6624

Closed
opened 2026-03-13 13:05:56 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6377
Author: @ping-maxwell
Created: 11/28/2025
Status: Merged
Merged: 1/8/2026
Merged by: @ping-maxwell

Base: canaryHead: feat/delete-anonymous-user


📝 Commits (10+)

  • c47cb43 feat(anonymous): delete anonymous user endpoint
  • 13408bf chore: lint
  • e277d5b Merge branch 'canary' into feat/delete-anonymous-user
  • b2aeabd Merge branch 'canary' into feat/delete-anonymous-user
  • 19ba4e8 Merge branch 'canary' into feat/delete-anonymous-user
  • 41bc3fa Merge branch 'canary' into feat/delete-anonymous-user
  • 1fc3802 chore: abstract anonymous session type
  • e89281b Merge branch 'canary' into feat/delete-anonymous-user
  • 80ebb38 fix: type errors
  • c6e5d4c Merge branch 'canary' into feat/delete-anonymous-user

📊 Changes

4 files changed (+152 additions, -14 deletions)

View changed files

📝 docs/content/docs/plugins/anonymous.mdx (+27 -2)
📝 packages/better-auth/src/plugins/anonymous/error-codes.ts (+3 -0)
📝 packages/better-auth/src/plugins/anonymous/index.ts (+117 -11)
📝 packages/better-auth/src/plugins/anonymous/types.ts (+5 -1)

📄 Description

Currently, there is no way to delete an anonymous user. Calling authClient.deleteUser requires a password, which anonymous users have not set.

This PR introduces a /delete-anonymous-user endpoint to allow such.

https://discord.com/channels/1288403910284935179/1443668195037679616


Summary by cubic

Adds a POST /delete-anonymous-user endpoint so anonymous users can delete their account and session without a password. Updates docs and error codes, and respects the plugin option to disable deletion.

  • New Features

    • Endpoint: POST /delete-anonymous-user; requires a valid session; deletes the user and clears the session cookie; returns { success: true }.
    • Guards: only works for anonymous users; errors for disabled deletion, non‑anonymous users, or failures.
    • Error codes: FAILED_TO_DELETE_ANONYMOUS_USER, USER_IS_NOT_ANONYMOUS, DELETE_ANONYMOUS_USER_DISABLED.
    • Docs: added “Delete Anonymous User” section and notes.
  • Migration

    • disableDeleteAnonymousUser now also blocks access to /delete-anonymous-user, in addition to stopping automatic deletion after account linking. Review this option if you rely on the new endpoint.

Written for commit 9c1b12faa9. Summary will update on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/6377 **Author:** [@ping-maxwell](https://github.com/ping-maxwell) **Created:** 11/28/2025 **Status:** ✅ Merged **Merged:** 1/8/2026 **Merged by:** [@ping-maxwell](https://github.com/ping-maxwell) **Base:** `canary` ← **Head:** `feat/delete-anonymous-user` --- ### 📝 Commits (10+) - [`c47cb43`](https://github.com/better-auth/better-auth/commit/c47cb43c44830d02c073aa65de0c01b309c01990) feat(anonymous): delete anonymous user endpoint - [`13408bf`](https://github.com/better-auth/better-auth/commit/13408bff41ec481f01c0786456ee7e1786b23338) chore: lint - [`e277d5b`](https://github.com/better-auth/better-auth/commit/e277d5b08a3b3ab2fd2a91da9e935c29f81f3914) Merge branch 'canary' into feat/delete-anonymous-user - [`b2aeabd`](https://github.com/better-auth/better-auth/commit/b2aeabdbe86ac78cbb40bf75c82ba86489bd8479) Merge branch 'canary' into feat/delete-anonymous-user - [`19ba4e8`](https://github.com/better-auth/better-auth/commit/19ba4e87f1861c2c6a4cac83b42b24c39e851549) Merge branch 'canary' into feat/delete-anonymous-user - [`41bc3fa`](https://github.com/better-auth/better-auth/commit/41bc3fa64f7ccf12d48c401fad5b83bf71bc661f) Merge branch 'canary' into feat/delete-anonymous-user - [`1fc3802`](https://github.com/better-auth/better-auth/commit/1fc38021a33bea8e23812edf83087146cf931dee) chore: abstract anonymous session type - [`e89281b`](https://github.com/better-auth/better-auth/commit/e89281ba00ea6c79229225a0af62522c469f925b) Merge branch 'canary' into feat/delete-anonymous-user - [`80ebb38`](https://github.com/better-auth/better-auth/commit/80ebb38aa39de6b2b4298d82c1559e56ba42ac79) fix: type errors - [`c6e5d4c`](https://github.com/better-auth/better-auth/commit/c6e5d4cca81d90cf28cdad838f9547eca096146e) Merge branch 'canary' into feat/delete-anonymous-user ### 📊 Changes **4 files changed** (+152 additions, -14 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/plugins/anonymous.mdx` (+27 -2) 📝 `packages/better-auth/src/plugins/anonymous/error-codes.ts` (+3 -0) 📝 `packages/better-auth/src/plugins/anonymous/index.ts` (+117 -11) 📝 `packages/better-auth/src/plugins/anonymous/types.ts` (+5 -1) </details> ### 📄 Description Currently, there is no way to delete an anonymous user. Calling authClient.deleteUser requires a password, which anonymous users have not set. This PR introduces a `/delete-anonymous-user` endpoint to allow such. https://discord.com/channels/1288403910284935179/1443668195037679616 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds a POST /delete-anonymous-user endpoint so anonymous users can delete their account and session without a password. Updates docs and error codes, and respects the plugin option to disable deletion. - **New Features** - Endpoint: POST /delete-anonymous-user; requires a valid session; deletes the user and clears the session cookie; returns { success: true }. - Guards: only works for anonymous users; errors for disabled deletion, non‑anonymous users, or failures. - Error codes: FAILED_TO_DELETE_ANONYMOUS_USER, USER_IS_NOT_ANONYMOUS, DELETE_ANONYMOUS_USER_DISABLED. - Docs: added “Delete Anonymous User” section and notes. - **Migration** - disableDeleteAnonymousUser now also blocks access to /delete-anonymous-user, in addition to stopping automatic deletion after account linking. Review this option if you rely on the new endpoint. <sup>Written for commit 9c1b12faa917b225e4805963c4ea8c7021f22314. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-03-13 13:05:56 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#6624