Skip to content

fix(user): user delete ends the user's sessions first - #2024

Open
AmanGIT07 wants to merge 1 commit into
mainfrom
fix/user-delete-ends-sessions
Open

AmanGIT07 wants to merge 1 commit into
mainfrom
fix/user-delete-ends-sessions

Conversation

@AmanGIT07

Copy link
Copy Markdown
Contributor

Summary

user.Service.Delete now ends the user's sessions before it removes the user's relations and the user row. Today the sessions go only because sessions.user_id references users with ON DELETE CASCADE, which fires on the hard delete. #2023 makes the user delete keep the row, so that cascade stops firing. Without this change, a request with a deleted user's session cookie would get not found instead of unauthenticated. This PR should be merged before #2023.

Changes

  • core/user/service.go: Delete first calls sessionService.DeleteByUserID, the same call Disable makes. A failure stops the delete before the relations and the row.

Technical Details

  • DeleteByUserID sets deleted_at on each live session of the user. A session with deleted_at set fails Session.IsValid, so the session authenticator skips it and the request is unauthenticated.
  • When an admin deletes a user, each live session gets a session.revoked audit record, as with DisableUser. No record is written when the actor is the session owner.
  • The expired session cleanup later removes these rows, 24 hours after deleted_at.

Test Plan

  • core/user/service_test.go TestService_Delete: the sessions end before the relations and the user row; a session failure stops the delete before the relations and the user; a relation failure stops it before the user. The cases fail without the session step, with the step after the relations, or with its error ignored.
  • e2e TestUserAPI case 13: a logged-in user is deleted by an admin, and the same session cookie then gets unauthenticated. On main this passes without the change too, because the hard delete still removes the sessions. With feat(store): user delete keeps the row #2023's soft delete applied locally, it passes with this change and fails without it: the cookie gets not found instead of unauthenticated.
  • go test ./core/user/... passes.
  • go test ./test/e2e/... passes.
  • golangci-lint run ./core/user/... ./test/e2e/regression/... reports no issues.

Delete soft-deletes the user's sessions before it removes the relations and the user row. Today the sessions go only through the sessions.user_id ON DELETE CASCADE, which stops firing once the user row is kept.
@vercel

vercel Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
frontier Ready Ready Preview Oct 25, 2026 8:13am UTC

@AmanGIT07 AmanGIT07 mentioned this pull request Oct 25, 2026
10 tasks done
@coderabbitai

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 78c1825 and c60c015.

Files selected for processing: 3
  • core/user/service.go
  • core/user/service_test.go
  • test/e2e/regression/api_test.go

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Deleting an account now also ends its active sessions. Requests made with those sessions are no longer authenticated after the account is deleted.

User deletion now removes the user’s sessions before deleting relations and the user record. Unit and API tests cover deletion order, failure handling, and session authentication after deletion.

Changes: User deletion

Layer / File(s) Summary
Delete sessions before user records
core/user/service.go, core/user/service_test.go
Service.Delete removes sessions before relations and the user record. Unit tests check the order and confirm that a session-deletion error stops the operation.
Check session after user deletion
test/e2e/regression/api_test.go
The regression test verifies that a request using the deleted user’s session fails with Unauthenticated.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: kushsharma

Merge Risk: Minimal · up to c60c0

Session cleanup now runs before user removal, and the deletion stops if cleanup fails. No established issue prevents merging after normal checks.

Pre-merge checks: Passed 2
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 40175772677

Coverage increased (+0.003%) to 55.732%

Details

  • Coverage increased (+0.003%) from the base build.
  • Patch coverage: 3 of 3 lines across 1 file are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 41929
Covered Lines: 23368
Line Coverage: 55.73%
Coverage Strength: 19.39 hits per line

💛 - Coveralls

This branch was successfully deployed

1 active deployment
Preview — c60c015e Deployed Oct 25, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants