Repository navigation
fix(user): user delete ends the user's sessions - #2024
Conversation
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.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 Summary
Merge Risk:
|
Coverage Report for CI Build 40498168490Warning Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes. Coverage increased (+0.01%) to 55.739%Details
Uncovered ChangesNo uncovered changes found. Coverage Regressions68 previously-covered lines in 2 files lost coverage.
Coverage Stats
💛 - Coveralls |
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.
There was a problem hiding this comment.
Actionable comments posted: 1

Review info
-
Run configuration-
- Source mode: Auto
- Repository: raystack/frontier
- Branch: fix/user-delete-ends-sessions
- File: .coderabbit.yaml
- Commit: 717deab
- Layers: Repository YAML
- Review profile: CHILL
- Plan: Advanced
- Run ID:
53066f08-b96b-4667-a2f6-3c9575e0b717
Files selected for processing: 2-
core/user/service.gocore/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.
-
Summary
user.Service.Deletenow ends the user's sessions after it removes the user's relations and before it deletes the user row. Today the sessions go only becausesessions.user_idreferencesuserswithON 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:DeletecallssessionService.DeleteByUserID, the same callDisablemakes, between the relations and the row. A failure stops the delete before the row.Technical Details
DeleteByUserIDsetsdeleted_aton each live session of the user. A session withdeleted_atset failsSession.IsValid, so the session authenticator skips it and the request is unauthenticated.session.revokedaudit record, as withDisableUser. No record is written when the actor is the session owner.deleted_at.Test Plan
core/user/service_test.goTestService_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.TestUserAPIcase 13: a logged-in user is deleted by an admin, and the same session cookie then gets unauthenticated. Onmainthis 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.