Skip to content

Auth: keep next after sign-in, so signing in from an invite accepts it - #407

Merged
baronunread merged 1 commit into
mainfrom
auth-keep-next
Oct 27, 2026
Merged

baronunread merged 1 commit into
mainfrom
auth-keep-next

Conversation

@baronunread

@baronunread baronunread commented Oct 27, 2026 •

Copy link
Copy Markdown
Owner

What was wrong

"Sign in to accept" on an invite goes to /login?next=/invite/<token>. Sign-in navigated there, but the login page rendered once more before it unmounted. On that render useSearchParams read the new location, the query string was gone, next fell back to /dashboard, and useRedirectWhenSignedIn (its effect depends on next) replaced the invite with the dashboard. The person was signed in but never joined the organization.

It was not specific to invites: any next was lost the same way. /login?next=/billing also landed on /dashboard, which likely affects the paid CTAs that send returning users through sign-in.

Found during the app audit while shooting the invite flow, reproduced twice in a clean browser and traced with a history.replaceState hook (/billing, then /dashboard).

Fix

src/app/routes/auth.tsx: read next once, in a useState initialiser, instead of on every render. The validation (must start with /, not //) is unchanged.

Tests

  • New e2e in tests/e2e/invites.pw.ts: an owner makes an invite link, a guest with an existing account signs out, opens the invite, clicks "Sign in to accept", signs in, lands back on /invite/<token>, accepts, and ends up a member of two orgs.
  • Mutation-tested: against main's auth.tsx the spec fails with Received: /dashboard; with the fix it passes.
  • Locally: auth.pw.ts, invites.pw.ts, first-run.pw.ts (18 passed), bun run verify (761 passed), bun run fallow clean.

No visible change, so no screenshots: the page the visitor lands on is the one they were already meant to reach.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Signing in from an invitation now returns you to that invitation after verification, so you can continue accepting it.
    • Redirects to invalid destinations continue to lead to the dashboard.

Signing in from "Sign in to accept" navigated to /invite/<token>, then the
login page rendered once more before unmounting, read the query string it
had just left (now empty), fell back to /dashboard, and useRedirectWhenSignedIn
replaced the invite. The person never joined. Every `next` was lost the
same way, /billing included.

Read `next` once, when the page mounts. New e2e: sign in from an invite,
land back on it, accept, and be a member. It fails on main (lands on
/dashboard) and passes here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between cc41902 and ee9402d.

Files selected for processing: 2
  • src/app/routes/auth.tsx
  • tests/e2e/invites.pw.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

The authentication flow now reads and validates its redirect destination once when it mounts. An end-to-end test covers signing up, signing in through an invite, returning to the invite, and accepting it.

Changes: Invite redirect flow

Layer / File(s) Summary
Preserve and verify invite redirects
src/app/routes/auth.tsx, tests/e2e/invites.pw.ts
useAuthFlow initializes the redirect destination once, using the pending verification’s next, the query parameter, or /dashboard in that order. The invite test checks that sign-in returns to the invite and that acceptance leaves the guest in two organizations.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: Minimal · up to ee940

The change preserves the sign-in destination, with no identified issue blocking merge.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly describes the main change: preserving the invite's next destination through sign-in so users can accept the invite.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within survi…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 2 files.

Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@github-actions

Copy link
Copy Markdown

React Doctor found no new issues. 🎉

Reviewed by React Doctor for commit ee9402d.

@github-actions

Copy link
Copy Markdown

leanest: 3 of 56 playwright test files selected

1 touches the change directly and the judge wasn't sure enough to skip 2.

Test Decision Reason
tests/e2e/invites.pw.ts RUN test file changed
tests/e2e/mcp-oauth.pw.ts RUN judge p=0.44 c=0.10
tests/e2e/auth.pw.ts RUN judge p=0.38 c=0.20
53 skipped
Test Decision Reason
tests/e2e/viewer-role.pw.ts SKIP judge p=0.16 c=0.58
tests/e2e/google-signin.pw.ts SKIP judge p=0.15 c=0.59
tests/e2e/self-host/no-providers.pw.ts SKIP judge p=0.13 c=0.63
tests/e2e/abuse-hold.pw.ts SKIP judge p=0.12 c=0.65
tests/e2e/authenticated-flows.pw.ts SKIP judge p=0.11 c=0.66
tests/e2e/click-caps.pw.ts SKIP judge p=0.10 c=0.68
tests/e2e/privacy-and-email-abuse.pw.ts SKIP judge p=0.08 c=0.71
tests/e2e/route-skeletons.pw.ts SKIP judge p=0.08 c=0.71
tests/e2e/admin-moderation.pw.ts SKIP judge p=0.07 c=0.73
tests/e2e/self-host/self-host.pw.ts SKIP judge p=0.07 c=0.73
tests/e2e/shell-persistence.pw.ts SKIP judge p=0.07 c=0.73
tests/e2e/abuse.pw.ts SKIP judge p=0.06 c=0.75
tests/e2e/admin-triage.pw.ts SKIP judge p=0.06 c=0.75
tests/e2e/account-deletion.pw.ts SKIP judge p=0.05 c=0.77
tests/e2e/anon-shortener.pw.ts SKIP judge p=0.05 c=0.77
tests/e2e/click-buffer.pw.ts SKIP judge p=0.05 c=0.77
tests/e2e/first-run.pw.ts SKIP judge p=0.05 c=0.77
tests/e2e/production/status-codes.pw.ts SKIP judge p=0.05 c=0.77
tests/e2e/turnstile-slot.pw.ts SKIP judge p=0.05 c=0.77
tests/e2e/billing-yearly.pw.ts SKIP judge p=0.04 c=0.78
tests/e2e/downgrade.pw.ts SKIP judge p=0.04 c=0.78
tests/e2e/link-addresses.pw.ts SKIP judge p=0.04 c=0.78
tests/e2e/link-states.pw.ts SKIP judge p=0.04 c=0.78
tests/e2e/api-keys.pw.ts SKIP judge p=0.03 c=0.80
tests/e2e/billing-truth.pw.ts SKIP judge p=0.03 c=0.80
tests/e2e/command-menu.pw.ts SKIP judge p=0.03 c=0.80
tests/e2e/link-risk.pw.ts SKIP judge p=0.03 c=0.80
tests/e2e/public-pages.pw.ts SKIP judge p=0.03 c=0.80
tests/e2e/api-method.pw.ts SKIP judge p=0.02 c=0.82
tests/e2e/avatar.pw.ts SKIP judge p=0.02 c=0.82
tests/e2e/billing-page.pw.ts SKIP judge p=0.02 c=0.82
tests/e2e/link-import.pw.ts SKIP judge p=0.02 c=0.82
tests/e2e/links-paging.pw.ts SKIP judge p=0.02 c=0.82
tests/e2e/new-link-live.pw.ts SKIP judge p=0.02 c=0.82
tests/e2e/pricing-page.pw.ts SKIP judge p=0.02 c=0.82
tests/e2e/production/seo.pw.ts SKIP judge p=0.02 c=0.82
tests/e2e/webmcp.pw.ts SKIP judge p=0.02 c=0.82
tests/e2e/analytics-export.pw.ts SKIP judge p=0.01 c=0.83
tests/e2e/anon-link-bar.pw.ts SKIP judge p=0.01 c=0.83
tests/e2e/default-domain.pw.ts SKIP judge p=0.01 c=0.83
tests/e2e/funnel.pw.ts SKIP judge p=0.01 c=0.83
tests/e2e/graphical-ui.pw.ts SKIP judge p=0.01 c=0.83
tests/e2e/landing-sections.pw.ts SKIP judge p=0.01 c=0.83
tests/e2e/not-found.pw.ts SKIP judge p=0.01 c=0.83
tests/e2e/production/csp.pw.ts SKIP judge p=0.01 c=0.83
tests/e2e/production/prerendered-pages.pw.ts SKIP judge p=0.01 c=0.83
tests/e2e/qr-download.pw.ts SKIP judge p=0.01 c=0.83
tests/e2e/qr-generator.pw.ts SKIP judge p=0.01 c=0.83
tests/e2e/header-float.pw.ts SKIP judge p=0.00 c=0.85
tests/e2e/hero-globe.pw.ts SKIP judge p=0.00 c=0.85
tests/e2e/page-ending.pw.ts SKIP judge p=0.00 c=0.85
tests/e2e/production/assets.pw.ts SKIP judge p=0.00 c=0.85
tests/e2e/utm-builder.pw.ts SKIP judge p=0.00 c=0.85

@baronunread
baronunread merged commit 333530b into main Oct 27, 2026
11 checks passed
@baronunread
baronunread deleted the auth-keep-next branch October 27, 2026 14:13
baronunread added a commit that referenced this pull request Oct 27, 2026
## Why

Checking a UI change meant seeding the database, finding the right
seeded person by hand, signing in and clicking through. Some states (a
domain past its grace period, a read-only org) took several minutes each
to reach. The coming redesign changes every screen, and each one needs
checking in every state, so reaching a state has to be one link.

We weighed recorded fixtures with a mocked `/api` against seeded
accounts on the real Worker. Fixtures give pixel-identical screenshots
but are a second copy of every API answer to keep in step, and they
would have hidden the invite bug (#407), which only showed against the
real Worker. Pixel-exact comparisons are planned for after the redesign
lands, when baselines stop changing in every PR (Playwright `page.route`
plus `page.clock`, baselines generated in CI).

## What

- `src/worker/dev-scenarios.ts`:
- `/__dev/scenarios` lists the states, each with links to every app
page.
- `/__dev/scenarios/<name>?to=/links` signs in as the seeded account in
that state through `auth.api.signInEmail`, sets the current org (and
dismisses the cookie banner) through a small hop page, and opens the
page.
- **Eleven scenarios:** `pro-owner`, `hobby-owner`, `free-owner`,
`fresh`, `member`, `viewer`, `over-plan`, `grace-ended`, `locked-org`,
`click-cap`, `admin`. Each is a SQL query over the seeded rows, so it
survives a re-seed and always lands on an account that really is in that
state.
- **Seeder:** adds the two states the random seed never produced,
`fresh.account@seed.test` (an empty org) and `platform.admin@seed.test`
(`is_admin`).
- **`AGENTS.md`:** documents the switcher next to the seed command.
- **`RESERVED_SLUGS`:** gains `__dev` (the drift guard in
`tests/util.test.ts` requires every Worker path to be reserved).

## Safety

- **Not in production builds.** `index.ts` imports the module
dynamically inside `if (import.meta.env.DEV)`. The first version used a
static import: the route answered 404 in production, but the whole
module, seed password included, was still in `dist/rdyrct/index.js`,
because Hono route registration counts as a side effect. The production
e2e now checks both the 404 and that no built file contains the seed
password.
- **Only seeded accounts.** It refuses any address that doesn't end in
`@seed.test`, and it can only sign in with the seeder's shared password.

## Tests

- `tests/e2e/dev-scenarios.pw.ts`: the list renders, an unknown scenario
is a 404, and a scenario on the unseeded e2e database answers 409 and
sets no cookie.
- `tests/e2e/production/status-codes.pw.ts`: in a built Worker the route
is a 404 and the code is absent.
- **By hand:** all 11 scenarios against a freshly seeded worktree
database. Each one signs in, and fresh, over-plan, read-only org,
grace-ended, click cap, admin and viewer each land on the right screen
in a browser.
- `bun run verify` and `bun run fallow` are green.

No user-facing change (dev builds only), so no screenshots.

Noticed while testing, not fixed here: the viewer of a downgraded org is
shown "See plans", which a viewer cannot act on.

🤖 Generated with [Claude Code](https://claude.com/claude-code)


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **New Features**
* Developers can browse seeded account scenarios in development builds
and sign in as a matching account to view the app in different states.
* Scenario links can open a chosen app page, with a default destination
when the requested page isn’t safe.
  * The scenario switcher is unavailable in production builds.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant