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

Closed
opened 2026-04-13 09:30:30 -05:00 by GiteaMirror · 0 comments
Owner

Original Pull Request: https://github.com/better-auth/better-auth/pull/5825

State: closed
Merged: Yes


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.

**Original Pull Request:** https://github.com/better-auth/better-auth/pull/5825 **State:** closed **Merged:** Yes --- # 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. -->
GiteaMirror added the pull-request label 2026-04-13 09:30:30 -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#14501