Skip to content

fix: guest verify#8939

Merged
csiyang merged 4 commits intomainfrom
siyangcao/nes-1521-fix-guest-email-verify
Mar 31, 2026
Merged

fix: guest verify#8939
csiyang merged 4 commits intomainfrom
siyangcao/nes-1521-fix-guest-email-verify

Conversation

@csiyang
Copy link
Copy Markdown
Contributor

@csiyang csiyang commented Mar 31, 2026

Summary by CodeRabbit

  • Bug Fixes

    • Fixed email verification flow for guest users transitioning to authenticated accounts; newly provided emails are now verified when needed, and users already verified are not redundantly re-verified.
    • Verification delivery failures are now handled gracefully and won't block account setup.
  • Improvements

    • Improved reliability of account setup and email handling for a smoother sign-in experience.
  • Tests

    • Added tests covering guest→authenticated conversion and verification behaviors.

@csiyang csiyang requested a review from mikeallisonJS March 31, 2026 20:58
@csiyang csiyang self-assigned this Mar 31, 2026
@stage-branch-merger
Copy link
Copy Markdown
Contributor

I see you added the "on stage" label, I'll get this merged to the stage branch!

@linear
Copy link
Copy Markdown

linear Bot commented Mar 31, 2026

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Mar 31, 2026

View your CI Pipeline Execution ↗ for commit e3ac9aa

Command Status Duration Result
nx affected --target=subgraph-check --base=ec44... ✅ Succeeded 1s View ↗
nx affected --target=extract-translations --bas... ✅ Succeeded <1s View ↗
nx affected --target=lint --base=ec44444820ef01... ✅ Succeeded <1s View ↗
nx affected --target=type-check --base=ec444448... ✅ Succeeded <1s View ↗
nx run-many --target=codegen --all --parallel=3 ✅ Succeeded 2s View ↗
nx run-many --target=prisma-generate --all --pa... ✅ Succeeded 4s View ↗

☁️ Nx Cloud last updated this comment at 2026-03-31 21:27:38 UTC

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 31, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: c99f1d0f-9bd9-4b0d-b0e5-2ffae2f0cf3c

📥 Commits

Reviewing files that changed from the base of the PR and between a1adba4 and e3ac9aa.

📒 Files selected for processing (2)
  • apis/api-users/src/schema/user/user.spec.ts
  • apis/api-users/src/schema/user/user.ts
✅ Files skipped from review due to trivial changes (1)
  • apis/api-users/src/schema/user/user.spec.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • apis/api-users/src/schema/user/user.ts

Walkthrough

Update to the me resolver: it now awaits the Prisma update, conditionally enqueues email verification (catching and logging enqueue errors), and includes three tests covering guest→authenticated conversion: verify invoked, verify not invoked when already verified, and enqueue failure handling.

Changes

Cohort / File(s) Summary
Resolver: me email verification
apis/api-users/src/schema/user/user.ts
Change me resolver to assign prisma.user.update result to updatedUser, call verifyUser(updatedUser.id, updatedUser.email, { app: 'NextSteps' }) only when updatedUser.emailVerified is falsy, wrap that call in its own try/catch and console.error failures instead of propagating. Preserves existing Prisma error handling (P2002 -> bad input).
Tests: guest→authenticated conversion
apis/api-users/src/schema/user/user.spec.ts
Add three tests: (1) stubs guest→authenticated update where emailVerified: false and asserts verifyUser is called with updated id/email and app 'NextSteps'; (2) same flow with emailVerified: true and asserts verifyUser is not called; (3) simulates verifyUser rejection and asserts the me response contains the updated email and no errors (enqueue failure is logged, not returned).

Sequence Diagram(s)

sequenceDiagram
    participant Client as Client
    participant Resolver as "me Resolver\n(src/schema/user/user.ts)"
    participant DB as "Prisma\nDatabase"
    participant Queue as "verifyUser\n(Email enqueue)"

    rect rgba(200,200,255,0.5)
    Client->>Resolver: call me query (with email)
    end

    rect rgba(200,255,200,0.5)
    Resolver->>DB: prisma.user.update(...) -> updatedUser
    DB-->>Resolver: updatedUser (email, emailVerified)
    end

    alt updatedUser.emailVerified == false
        rect rgba(255,230,200,0.5)
        Resolver->>Queue: verifyUser(updatedUser.id, updatedUser.email, {app:'NextSteps'})
        alt enqueue succeeds
            Queue-->>Resolver: enqueued
        else enqueue fails
            Queue--x Resolver: error
            Resolver->>Resolver: console.error(error)
        end
        end
    else already verified
        Note over Resolver: no verifyUser call
    end

    Resolver-->>Client: return updatedUser (no errors)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'fix: guest verify' is vague and does not clearly convey what is being fixed or what aspect of guest verification is involved. Use a more descriptive title that specifies the particular issue being fixed, such as 'fix: enqueue email verification when converting guest to authenticated user' or 'fix: email verification flow for guest→authenticated conversion'.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch siyangcao/nes-1521-fix-guest-email-verify

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 and usage tips.

@csiyang csiyang changed the title fix guest verify fix: guest verify Mar 31, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@apis/api-users/src/schema/user/user.ts`:
- Around line 121-128: The current code awaits verifyUser(...) after updating
the user, so if enqueueing verification rejects it causes the whole me query to
fail; change this by decoupling verification from the happy path: after
detecting updatedUser.emailVerified is falsy, invoke verifyUser with the same
arguments (ctx.currentUser.id, ctx.currentUser.email, input?.redirect,
input?.app ?? 'NextSteps') but do not let its failure bubble up — either call it
without awaiting (fire-and-forget) or wrap the await in a try/catch and log the
error (don’t rethrow), ensuring the user update result is returned even if
verification enqueue fails.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 8eb2ee5d-3c47-4a79-affc-49fdd68683cb

📥 Commits

Reviewing files that changed from the base of the PR and between ec44444 and a1adba4.

📒 Files selected for processing (2)
  • apis/api-users/src/schema/user/user.spec.ts
  • apis/api-users/src/schema/user/user.ts

Comment thread apis/api-users/src/schema/user/user.ts
mikeallisonJS
mikeallisonJS previously approved these changes Mar 31, 2026
@csiyang csiyang added this pull request to the merge queue Mar 31, 2026
Merged via the queue into main with commit fa51973 Mar 31, 2026
22 checks passed
@csiyang csiyang deleted the siyangcao/nes-1521-fix-guest-email-verify branch March 31, 2026 23:06
tanflem pushed a commit that referenced this pull request Apr 3, 2026
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants