Repository navigation
Auth: keep next after sign-in, so signing in from an invite accepts it - #407
Conversation
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>
|
No actionable comments were generated in the recent review.
|
| 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:
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: 
5
-
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.
Comment @coderabbitai help to get the list of available commands.
|
React Doctor found no new issues. 🎉 Reviewed by React Doctor for commit |
leanest: 3 of 56 playwright test files selected1 touches the change directly and the judge wasn't sure enough to skip 2.
53 skipped
|
## 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>
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 renderuseSearchParamsread the new location, the query string was gone,nextfell back to/dashboard, anduseRedirectWhenSignedIn(its effect depends onnext) replaced the invite with the dashboard. The person was signed in but never joined the organization.It was not specific to invites: any
nextwas lost the same way./login?next=/billingalso 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.replaceStatehook (/billing, then/dashboard).Fix
src/app/routes/auth.tsx: readnextonce, in auseStateinitialiser, instead of on every render. The validation (must start with/, not//) is unchanged.Tests
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.main'sauth.tsxthe spec fails withReceived: /dashboard; with the fix it passes.auth.pw.ts,invites.pw.ts,first-run.pw.ts(18 passed),bun run verify(761 passed),bun run fallowclean.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