[PR #5825] [MERGED] fix(anonymous): prevent Convex cleanup from deleting fresh sessions #23155

Closed
opened 2026-04-15 21:31:13 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5825
Author: @rodrigosdev
Created: 11/7/2025
Status: Merged
Merged: 1/8/2026
Merged by: @Bekacru

Base: canaryHead: canary


📝 Commits (3)

  • 5c472af feat(anonymous): implement safeguards for anonymous user cleanup during session linking
  • 98e7114 fix(tests): remove duplicate import of apiModule in anon.test.ts
  • 1632171 Merge branch 'canary' into canary

📊 Changes

2 files changed (+122 additions, -2 deletions)

View changed files

📝 packages/better-auth/src/plugins/anonymous/anon.test.ts (+110 -0)
📝 packages/better-auth/src/plugins/anonymous/index.ts (+12 -2)

📄 Description

Summary

  • Guard the anonymous post-auth middleware so it only deletes the previous anonymous account when linking to a new, non-anonymous user.This keeps newly created Convex anonymous users alive and fixes #5824.
  • Leave the onLinkAccount callback behavior unchanged, ensuring integrators can still migrate data before cleanup runs.
  • Add regression tests that mock the middleware context for both the Convex-style “same anonymous session” flow (no deletion occurs) and the standard linking flow (cleanup still runs).

Testing

pnpm --filter @better-auth/core build
pnpm --filter @better-auth/telemetry build
pnpm --filter better-auth exec vitest run src/plugins/anonymous/anon.test.ts

Breaking Changes

None.

Checklist

[x] Tests added/updated for the new behavior
[x] All targeted tests passing locally
[x] References the reported bug better-auth/better-auth#5824


Summary by cubic

Prevents anonymous cleanup from deleting a newly created anonymous session when linking. Keeps Convex anonymous sessions intact until a non-anonymous account is linked; fixes #5824.

  • Bug Fixes
    • Guard post-auth to skip deletion when the new session user is the same or still anonymous; only delete the previous anonymous user when linking to a non-anonymous account.
    • Keep onLinkAccount callback behavior unchanged so data migration still runs before cleanup.
    • Add regression tests for both same-session anonymous and standard linking flows.

Written for commit 163217199f. 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/5825 **Author:** [@rodrigosdev](https://github.com/rodrigosdev) **Created:** 11/7/2025 **Status:** ✅ Merged **Merged:** 1/8/2026 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `canary` --- ### 📝 Commits (3) - [`5c472af`](https://github.com/better-auth/better-auth/commit/5c472afdefbe95f9046b6d2b39a7b9de00686a90) feat(anonymous): implement safeguards for anonymous user cleanup during session linking - [`98e7114`](https://github.com/better-auth/better-auth/commit/98e7114ed5126170da781bac5f188b6719e1ab8c) fix(tests): remove duplicate import of apiModule in anon.test.ts - [`1632171`](https://github.com/better-auth/better-auth/commit/163217199fa29751cca6d85e58c620a7e33edfaa) Merge branch 'canary' into canary ### 📊 Changes **2 files changed** (+122 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/anonymous/anon.test.ts` (+110 -0) 📝 `packages/better-auth/src/plugins/anonymous/index.ts` (+12 -2) </details> ### 📄 Description # Summary - Guard the anonymous post-auth middleware so it only deletes the previous anonymous account when linking to a new, non-anonymous user.This keeps newly created Convex anonymous users alive and fixes #5824. - Leave the onLinkAccount callback behavior unchanged, ensuring integrators can still migrate data before cleanup runs. - Add regression tests that mock the middleware context for both the Convex-style “same anonymous session” flow (no deletion occurs) and the standard linking flow (cleanup still runs). # Testing ``` pnpm --filter @better-auth/core build pnpm --filter @better-auth/telemetry build pnpm --filter better-auth exec vitest run src/plugins/anonymous/anon.test.ts ``` # Breaking Changes None. # Checklist [x] Tests added/updated for the new behavior [x] All targeted tests passing locally [x] References the reported bug better-auth/better-auth#5824 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Prevents anonymous cleanup from deleting a newly created anonymous session when linking. Keeps Convex anonymous sessions intact until a non-anonymous account is linked; fixes #5824. - **Bug Fixes** - Guard post-auth to skip deletion when the new session user is the same or still anonymous; only delete the previous anonymous user when linking to a non-anonymous account. - Keep onLinkAccount callback behavior unchanged so data migration still runs before cleanup. - Add regression tests for both same-session anonymous and standard linking flows. <sup>Written for commit 163217199fa29751cca6d85e58c620a7e33edfaa. 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-04-15 21:31:13 -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#23155