Skip to content

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

Merged
AmanGIT07 merged 2 commits into
mainfrom
fix/user-delete-ends-sessions
Oct 27, 2026
Merged

AmanGIT07 merged 2 commits into
mainfrom
fix/user-delete-ends-sessions

Conversation

@AmanGIT07

@AmanGIT07 AmanGIT07 commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

user.Service.Delete now ends the user's sessions after it removes the user's relations and before it deletes 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 calls sessionService.DeleteByUserID, the same call Disable makes, between the relations and the row. A failure stops the delete before the row.

Technical Details

  • The sessions end as the last step before the row, which is when the cascade ends them today. If an earlier step fails, the user row is still live and the user stays signed in, so they can retry.
  • 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 relations go first, then the sessions, then the user row; a relation failure stops the delete before the sessions and the user; a session failure stops it before the user. The cases fail without the session step, with the step before the relations or after the row, 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 27, 2026 11:43am UTC

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

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 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 relations, then sessions, and then the user record. Tests cover deletion order, failure handling, and session authentication after deletion.

Changes: User deletion

Layer / File(s) Summary
Delete relations and sessions before the user record
core/user/service.go, core/user/service_test.go
Service.Delete deletes sessions after relation deletion and before deleting the user. Unit tests verify this order and that failures stop later operations.
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: Low · up to 717de

User deletion can leave inaccurate revocation events for sessions that were already invalid.

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

coveralls commented Oct 25, 2026 •

Copy link
Copy Markdown

Coverage Report for CI Build 40498168490

Warning

Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes.
Quick fix: rebase this PR. Learn more →

Coverage increased (+0.01%) to 55.739%

Details

  • Coverage increased (+0.01%) from the base build.
  • Patch coverage: 3 of 3 lines across 1 file are fully covered (100%).
  • 68 coverage regressions across 2 files.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

68 previously-covered lines in 2 files lost coverage.

File Lines Losing Coverage Coverage
internal/api/v1beta1connect/organization.go 36 63.35%
internal/store/postgres/organization_repository.go 32 79.31%

Coverage Stats

Coverage Status
Relevant Lines: 41940
Covered Lines: 23377
Line Coverage: 55.74%
Coverage Strength: 19.5 hits per line

💛 - Coveralls

Comment thread core/user/service.go Outdated
Delete now removes the relations first, then ends the sessions, then deletes the row. If the relations step fails, the user stays signed in and can retry.
@AmanGIT07 AmanGIT07 changed the title fix(user): user delete ends the user's sessions first fix(user): user delete ends the user's sessions Oct 27, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


Review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between c60c015 and 717deab.

Files selected for processing: 2
  • core/user/service.go
  • core/user/service_test.go

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

Comment thread core/user/service.go
@AmanGIT07
AmanGIT07 merged commit d564023 into main Oct 27, 2026
8 checks passed
@AmanGIT07
AmanGIT07 deleted the fix/user-delete-ends-sessions branch October 27, 2026 11:51

This branch was successfully deployed

1 active deployment
Preview — 717deab6 Deployed Oct 27, 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.

3 participants