fix: Restore soft-deleted users on re-authentication#106
Open
mkrokosz wants to merge 2 commits intoopenclaw:mainfrom
Open
fix: Restore soft-deleted users on re-authentication#106mkrokosz wants to merge 2 commits intoopenclaw:mainfrom
mkrokosz wants to merge 2 commits intoopenclaw:mainfrom
Conversation
Users who deleted their account were unable to sign in again with the same GitHub account. The OAuth flow would complete but the user would remain logged out due to the `deletedAt` field being set. This fix adds a `createOrUpdateUser` callback that: 1. Detects soft-deleted users during OAuth 2. Checks audit logs to determine if user was BANNED vs SELF-DELETED 3. If banned → throws error "This account has been suspended" 4. If self-deleted → clears `deletedAt` to restore account Security: Both `deleteAccount` and `banUser` set the same `deletedAt` field. This fix ensures banned users cannot restore their accounts. Performance: The callback runs on every sign-in, but the audit log query ONLY executes for soft-deleted users (rare edge case). Normal active users just hit a single `if` check - no extra queries. When the audit log query does run, it uses the `by_target` index for efficient lookup. Co-Authored-By: Claude Opus 4.5 <[email protected]>
Contributor
|
@mkrokosz is attempting to deploy a commit to the Amantus Machina Team on Vercel. A member of the Team first needs to authorize it. |
The auditLogs.targetId field is v.string() in the schema, so explicitly convert the Id<'users'> to string to ensure type-safe comparison. Co-Authored-By: Claude Opus 4.5 <[email protected]>
ec6a17d to
9fc36ba
Compare
|
@steipete pls get this one merged |
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
Users who deleted their ClawHub account cannot sign in again with the same GitHub account. This PR fixes that by restoring self-deleted accounts on re-authentication.
The Problem
When a user deletes their account:
deletedAttimestamp is set (soft-delete)When they try to sign in again:
mequery filters deleted users:if (!user || user.deletedAt) return nullThe Fix
Adds a
createOrUpdateUsercallback inconvex/auth.tsthat:deletedAtto restore accountSecurity Consideration
Both
deleteAccountandbanUserset the samedeletedAtfield. This fix ensures banned users cannot restore their accounts by re-authenticating - only self-deleted users can restore.Performance
The callback runs on every OAuth sign-in, but:
nullimmediatelyifcheck on already-loaded fieldauditLogs.by_targetFor 99% of logins (active users), there is zero performance impact. The audit log query only runs for soft-deleted users attempting to sign in, and uses the existing
by_targetindex.Testing
🤖 Generated with Claude Code
Greptile Overview
Greptile Summary
This PR adds a
callbacks.createOrUpdateUserhook inconvex/auth.tsto restore soft-deleted user records when the same GitHub account re-authenticates. The callback:nullwhen there is noexistingUserId).auditLogs.by_targetindex for auser.banrecord and blocks login with a suspension error if present; otherwise it clearsdeletedAtand updatesupdatedAtto restore the account.This aligns the auth flow with the existing
me/requireUserbehavior that filters outdeletedAtusers, while preserving bans by treating ban audit logs as the source of truth.Confidence Score: 4/5
user.banaudit logs), and avoids extra queries for normal logins. The main concern is a minor schema/type mismatch (auditLogs.targetIdisstringwhile code compares against anId<'users'>), which could make the ban check brittle depending on how IDs are serialized in practice.(2/5) Greptile learns from your feedback when you react with thumbs up/down!
Context used:
dashboard- AGENTS.md (source)