Skip to content

fix(auth): stop signup auth-watcher from racing past email verification - #4528

Merged
PierreBrisorgueil merged 2 commits into
masterfrom
fix/4437-signup-verification-race
Aug 3, 2026
Merged

fix(auth): stop signup auth-watcher from racing past email verification#4528
PierreBrisorgueil merged 2 commits into
masterfrom
fix/4437-signup-verification-race

Conversation

@PierreBrisorgueil

@PierreBrisorgueil PierreBrisorgueil commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Bug

On a signup that requires email verification, the user could be dropped straight into the app WITHOUT ever seeing the "check your inbox" step — when organizations are disabled, or when the server-config fetch returned null.

signup.view.vue's watch.auth called pushAfterAuth() as soon as the store flipped auth = true (set synchronously inside signup()). That pre-flush watcher job lands on an earlier microtask than validate()'s own await authStore.signup() continuation, so on the !serverConfig?.organizations?.enabled path (also true when serverConfig === null after a failed config fetch) the watcher could navigate into the app before validate() reached the emailVerificationRequired branch and set signupStep = 'emailVerification' — silently skipping the verification gate. No router guard enforces email-verified downstream, so nothing caught it.

The existing unit suite mocked useAuthStore with a static { auth: false } object — the component's auth computed never changed, so the watcher never fired in tests, masking the race entirely.

Fix

validate() already calls pushAfterAuth() in every terminal branch where navigation should happen, so the watcher's fast-path push was redundant as well as unsafe. Removed the watch.auth handler (and the now-unused auth computed) entirely. OAuth's full-page href redirects (handled in created()) are unaffected.

Test

Added auth.signup.view.race.unit.tests.js, which runs the real Pinia auth store (only network/analytics/ability are mocked) so auth flips via genuine reactivity, reproducing the actual microtask race. Both tests:

  • fail against master's behavior (proves the race: router.push('/tasks') fires before the verification step is shown)
  • pass with the fix

Covers: organizations disabled + emailVerificationRequired, and the serverConfig === null (failed config fetch) path.

Closes #4437

Summary by CodeRabbit

  • Bug Fixes

    • Improved signup behavior during email verification.
    • Prevented unintended navigation while authentication and configuration data are loading or unavailable.
    • Ensured signup reaches the email verification step reliably when organization features are disabled.
  • Tests

    • Added regression coverage for successful and failed configuration-loading scenarios during signup.

watch.auth called pushAfterAuth() as soon as signup() flipped
authStore.auth to true. That pre-flush watcher job lands on an earlier
microtask than validate()'s own `await authStore.signup()` continuation,
so on the organizations-disabled path (including serverConfig === null
after a failed config fetch) it could navigate into the app before
validate() reached the emailVerificationRequired branch and set
signupStep to 'emailVerification' — silently skipping the verification
gate.

validate() already calls pushAfterAuth() in every terminal branch, so
the watcher's fast-path push was redundant as well as unsafe; removed
it (and the now-unused `auth` computed) entirely. OAuth's full-page
href redirects (handled in created()) are unaffected.

Adds a regression suite that runs the real Pinia auth store (the
existing suite mocks a static { auth: false } store, so the watcher
never fired and the race was untested) and confirms the fix against
both the organizations-disabled and serverConfig-null paths.

Closes #4437
@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@PierreBrisorgueil, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 55 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 88d2deae-174c-45e7-87ce-a85924609182

📥 Commits

Reviewing files that changed from the base of the PR and between 7234d08 and e99705a.

📒 Files selected for processing (1)
  • src/modules/auth/tests/auth.signup.view.race.unit.tests.js

Walkthrough

The signup view no longer redirects from authentication watcher updates. A real-store Vitest suite verifies that email verification remains visible and navigation does not occur when server configuration succeeds or fails.

Changes

Signup email verification flow

Layer / File(s) Summary
Remove signup authentication redirect
src/modules/auth/views/signup.view.vue
Removes the auth computed property and the watcher that redirected authenticated users from the signup form.
Validate signup race scenarios
src/modules/auth/tests/auth.signup.view.race.unit.tests.js
Adds two real-store tests for email verification with organizations disabled, including a failed server configuration request where serverConfig is null.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant SignupView
  participant AuthStore
  participant Router
  SignupView->>AuthStore: submit signup
  AuthStore-->>SignupView: emailVerificationRequired
  SignupView->>SignupView: show emailVerification step
  SignupView-->>Router: no navigation
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the auth signup race and the email-verification impact.
Description check ✅ Passed The description clearly covers the bug, fix, affected paths, regression tests, and linked issue.
Linked Issues check ✅ Passed The changes remove the unsafe watcher and add reactive regression tests for both issue #4437 failure paths.
Out of Scope Changes check ✅ Passed The changes are limited to the signup view and targeted regression tests required by issue #4437.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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 fix/4437-signup-verification-race

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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 current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/modules/auth/tests/auth.signup.view.race.unit.tests.js`:
- Around line 22-46: Add JSDoc headers to each new mock factory in the vi.mock
calls and to the ability.can callback, including a one-line description and an
`@returns` annotation with the appropriate type; include `@param` annotations if any
callback arguments are present. Leave test and lifecycle callbacks unchanged, as
the exemption applies only to those APIs.
🪄 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: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: f63165ad-f85c-4be7-931c-4de235eb1e86

📥 Commits

Reviewing files that changed from the base of the PR and between 38c1b9a and 7234d08.

📒 Files selected for processing (2)
  • src/modules/auth/tests/auth.signup.view.race.unit.tests.js
  • src/modules/auth/views/signup.view.vue
💤 Files with no reviewable changes (1)
  • src/modules/auth/views/signup.view.vue

Comment thread src/modules/auth/tests/auth.signup.view.race.unit.tests.js
@codecov

codecov Bot commented Aug 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.57%. Comparing base (41ffdf8) to head (e99705a).
⚠️ Report is 14 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4528   +/-   ##
=======================================
  Coverage   99.57%   99.57%           
=======================================
  Files          36       36           
  Lines        1411     1411           
  Branches      439      439           
=======================================
  Hits         1405     1405           
  Misses          6        6           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Addresses CodeRabbit review on #4528 — vi.mock() factories and the
ability.can stub were missing the one-line description + @returns the
repo's coding guideline requires for non-test/lifecycle callbacks.
@PierreBrisorgueil
PierreBrisorgueil merged commit cbf4947 into master Aug 3, 2026
7 checks passed
@PierreBrisorgueil
PierreBrisorgueil deleted the fix/4437-signup-verification-race branch August 3, 2026 09:51
PierreBrisorgueil added a commit that referenced this pull request Aug 3, 2026
…ate() (#4534)

* fix(auth): stop signin auth-watcher from racing navigation past validate()

watch.auth was the sole navigator on signin: it pushed the redirect
route as soon as signin() flipped authStore.auth to true. That
pre-flush watcher job lands on an earlier microtask than validate()'s
own `await authStore.signin()` continuation, decoupling navigation
from the flow that triggered it. Any future step added after the
awaited signin() (MFA challenge, forced password rotation, consent
interstitial) would be silently skipped before it could run -
reproducing #4437's bug class (fixed for signup in #4528) on this view.

Moves navigation into validate()'s success path, explicitly after
authStore.signin() resolves and authStore.auth is true, preserving the
redirect-query behavior byte-for-byte (including the startsWith('/')
open-redirect guard). Removes the now-unused watch.auth handler and
auth computed. OAuth's full-page href redirects (handled in created())
are unaffected.

Adds a regression suite that runs the real Pinia auth store (the
existing suite mocks a static { auth: false } store, so the watcher
never fired and the race was untested) covering the default-route
branch, the redirect-query branch, the non-"/"-prefixed redirect guard,
and the failed-signin (no navigation) branch.

Closes #4533

* refactor(simplify): extract submitSignin helper in the #4533 race suite

Cuts the fill-email/fill-password/validate/flushPromises sequence that
repeated verbatim across all 4 tests into one submitSignin() helper.
Keeps each scenario as its own named it() block (each documents a
distinct, security-relevant redirect case) rather than collapsing into
a test.each table.
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.

🐛 fix(auth): signup auth-watcher races validate() → skips email-verification gate

1 participant