fix(users): detach portal users instead of deleting against RESTRICT FKs - #368
Merged
Conversation
Chat and posts restrict principal deletes, so Remove from portal failed silently. Anonymize the principal (keep the user row) and toast mutation failures. Closes #363
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Detach alone left the Better-Auth cookie live, so getOptionalAuth provisioned a new principal on the next request. Drop sessions in the same transaction as the anonymize update.
Bootstrap caches type/role per user for 5 minutes. Invalidate it after detach so a later sign-in cannot reuse the removed principal.
Spreading unknown[] into a two-arg mock failed TS2556 on the check job. Accept rest parameters so the factory typechecks.
mortondev
force-pushed
the
fix/remove-portal-user-chat-fk
branch
from
August 14, 2026 15:22
fa884e5 to
7358887
Compare
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
Null conversation visitorEmail in the same transaction, treat cache invalidation as best-effort, and mint a fresh principal when identify finds a detached user row.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Admin → Users → Remove from portal deleted the principal. Chat conversations/messages (and posts/comments) are
ON DELETE RESTRICT, so Postgres failed, React Query rolled back, and no toast was shown.Deleting would also drop history. Instead we detach: clear
userId, mark the principal anonymous as “Removed user”, keep the Better-Auth user so a later sign-in provisions a fresh principal. The users list inner-joinsuser, so they disappear immediately. Failures now toast.Closes #363
Test plan
Verified locally against Docker Postgres (transaction rollback): detach clears visitorEmail/sessions, remints a new principal on identify, authored posts stay as Removed user, inner-join list omits the detached row.