Skip to content

fix: email redirect#8955

Merged
csiyang merged 12 commits intomainfrom
siyangcao/nes-1525-email-verification-redirects-to-dashboard-instead-of
Apr 8, 2026
Merged

fix: email redirect#8955
csiyang merged 12 commits intomainfrom
siyangcao/nes-1525-email-verification-redirects-to-dashboard-instead-of

Conversation

@csiyang
Copy link
Copy Markdown
Contributor

@csiyang csiyang commented Apr 6, 2026

Summary by CodeRabbit

  • Bug Fixes

    • Email verification via email+token now validates early and redirects to terms on success; failed validations return the verification page without triggering prior session checks.
    • Redirect logic now safely decodes incoming redirect params, encodes outgoing links, enforces open-redirect protections, and correctly routes users (including root/no-redirect and teams/new flows).
  • Tests

    • Added tests covering redirect decoding/encoding, terms-and-conditions and teams navigation, and open-redirect protection cases.

@csiyang csiyang requested a review from mikeallisonJS April 6, 2026 23:56
@csiyang csiyang self-assigned this Apr 6, 2026
@linear
Copy link
Copy Markdown

linear Bot commented Apr 6, 2026

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Apr 6, 2026

View your CI Pipeline Execution ↗ for commit 88dce4e

Command Status Duration Result
nx run journeys-admin-e2e:e2e ✅ Succeeded 28s View ↗
nx run-many --target=vercel-alias --projects=jo... ✅ Succeeded 2s View ↗
nx run-many --target=upload-sourcemaps --projec... ✅ Succeeded 10s View ↗
nx run-many --target=deploy --projects=journeys... ✅ Succeeded 1m View ↗

☁️ Nx Cloud last updated this comment at 2026-04-08 02:31:08 UTC

@github-actions github-actions Bot temporarily deployed to Preview - journeys-admin April 6, 2026 23:58 Inactive
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 7, 2026

The latest updates on your projects.

Name Status Preview Updated (UTC)
journeys-admin ✅ Ready journeys-admin preview Wed Apr 8 14:28:07 NZST 2026

mikeallisonJS
mikeallisonJS previously approved these changes Apr 7, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 7, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Server-side verify now validates email+token via VALIDATE_EMAIL first and redirects on success; on validation failure it returns page props and skips the prior GET_ME "already verified" check. Redirect parsing was refactored to separate raw and URL-encoded redirect values.

Changes

Cohort / File(s) Summary
Email verification page
apps/journeys-admin/pages/users/verify.tsx
When email+token present, call VALIDATE_EMAIL first; on success perform redirectToApp(ctx); on failure return props (email, token, initialError: null, userSerialized, translations, initialApolloState) and do not run GET_ME.
Conditional redirect logic
apps/journeys-admin/src/libs/checkConditionalRedirect/checkConditionalRedirect.ts
Parse ?redirect= from resolvedUrl into a validated raw currentRedirect and an encodedRedirect; pass raw redirect into GET_ME variables and use encodedRedirect when appending query strings; add branch: if terms accepted and current route is /users/terms-and-conditions, redirect to /teams/new when no teams else to currentRedirect ?? '/'.
Redirect behavior tests
apps/journeys-admin/src/libs/checkConditionalRedirect/checkConditionalRedirect.spec.tsx
Added tests for accepted-terms flows, ensuring apolloClient.query receives decoded variables.input.redirect, root / becomes undefined, resolvedUrl is used when no redirect param, and open-redirect/protocol-relative cases fall back to safe destinations.

Sequence Diagram(s)

sequenceDiagram
    participant Browser
    participant SSR as Server (getServerSideProps)
    participant API as GraphQL
    Browser->>SSR: GET /users/verify?email=...&token=...(&redirect=...)
    SSR->>API: VALIDATE_EMAIL(email, token)
    alt VALIDATE_EMAIL succeeds
        API-->>SSR: success
        SSR-->>Browser: HTTP redirect -> /users/terms-and-conditions (with encoded redirect if provided) or redirectToApp(ctx)
    else VALIDATE_EMAIL fails
        API-->>SSR: error
        SSR-->>Browser: render verify page with props (email, token, initialError: null, initialApolloState)
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The PR title 'fix: email redirect' is vague and does not clearly convey the specific changes made. While it refers to email-related redirect functionality, it lacks sufficient detail to distinguish this fix from other potential email redirect issues. Consider a more descriptive title such as 'fix: handle email verification redirect logic with conditional team checks' or 'fix: improve email verification flow with proper redirect handling'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch siyangcao/nes-1525-email-verification-redirects-to-dashboard-instead-of

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.

@github-actions github-actions Bot requested a deployment to Preview - journeys-admin April 7, 2026 02:15 Pending
@github-actions github-actions Bot temporarily deployed to Preview - journeys-admin April 7, 2026 02:19 Inactive
csiyang and others added 2 commits April 7, 2026 21:52
Merge main to incorporate guest login flow fixes from #8945.
Resolved conflict in verify.tsx by taking main's simplified
redirectToApp approach.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot temporarily deployed to Preview - journeys-admin April 7, 2026 21:54 Inactive
@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!

stage-branch-merger Bot added a commit that referenced this pull request Apr 7, 2026
stage-branch-merger Bot added a commit that referenced this pull request Apr 7, 2026
@github-actions github-actions Bot temporarily deployed to Preview - journeys-admin April 7, 2026 22:40 Inactive
stage-branch-merger Bot added a commit that referenced this pull request Apr 7, 2026
stage-branch-merger Bot added a commit that referenced this pull request Apr 7, 2026
@github-actions github-actions Bot temporarily deployed to Preview - journeys-admin April 7, 2026 23:59 Inactive
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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/journeys-admin/pages/users/verify.tsx (1)

265-273: ⚠️ Potential issue | 🟠 Major

Use the query email in the fallback render path.

This catch path is the exact stale-cookie fallback, but ValidateEmail still ignores props.email and derives the address from user?.email. If the SSR cookie belongs to another account, the page can render and retry against the wrong email.

🔧 Suggested fix
 function ValidateEmail({
+  email: initialEmail,
   token,
   initialError = null
 }: ValidateEmailProps): ReactElement {
   const { t } = useTranslation('apps-journeys-admin')
   const router = useRouter()
   const client = useApolloClient()
   const { user } = useAuth()
-  const email = user?.email ?? ''
+  const email = initialEmail ?? user?.email ?? ''
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/journeys-admin/pages/users/verify.tsx` around lines 265 - 273, The
fallback/stale-cookie path currently derives the address from user?.email
instead of the SSR-provided prop; update the ValidateEmail render logic to use
the incoming prop email (props.email) as the source of truth when present and
only fall back to user?.email if props.email is missing, so the
retry/confirmation flow targets the SSR-provided address rather than an account
from a stale cookie. Locate the Verify page component and the ValidateEmail
usage/implementation and change the email selection to prefer the email prop,
and ensure any validation/errors/messages also reference props.email in that
code path.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@apps/journeys-admin/src/libs/checkConditionalRedirect/checkConditionalRedirect.ts`:
- Around line 47-52: Reject external/non-app-relative redirect values before
using them: in checkConditionalRedirect (variables currentRedirect, resolvedUrl,
redirect, encodedRedirect) validate that any candidate redirect is an internal
path (e.g., begins with a single "/" and does not start with "//" or contain a
scheme like "http://" or "https://") before assigning redirect or building
encodedRedirect; if validation fails, ignore that candidate and fall back to
resolvedUrl or default behavior. Apply the same validation logic to the other
branch referenced in the file (the block handling lines ~92-105) so both places
only reuse safe internal paths.

---

Outside diff comments:
In `@apps/journeys-admin/pages/users/verify.tsx`:
- Around line 265-273: The fallback/stale-cookie path currently derives the
address from user?.email instead of the SSR-provided prop; update the
ValidateEmail render logic to use the incoming prop email (props.email) as the
source of truth when present and only fall back to user?.email if props.email is
missing, so the retry/confirmation flow targets the SSR-provided address rather
than an account from a stale cookie. Locate the Verify page component and the
ValidateEmail usage/implementation and change the email selection to prefer the
email prop, and ensure any validation/errors/messages also reference props.email
in that code path.
🪄 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: 90f48592-c138-4dd8-b7a8-9b2805217ee3

📥 Commits

Reviewing files that changed from the base of the PR and between 17f207f and 4936076.

📒 Files selected for processing (3)
  • apps/journeys-admin/pages/users/verify.tsx
  • apps/journeys-admin/src/libs/checkConditionalRedirect/checkConditionalRedirect.spec.tsx
  • apps/journeys-admin/src/libs/checkConditionalRedirect/checkConditionalRedirect.ts

stage-branch-merger Bot added a commit that referenced this pull request Apr 8, 2026
@github-actions github-actions Bot requested a deployment to Preview - journeys-admin April 8, 2026 01:56 Pending
stage-branch-merger Bot added a commit that referenced this pull request Apr 8, 2026
@github-actions github-actions Bot temporarily deployed to Preview - journeys-admin April 8, 2026 01:59 Inactive
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
`@apps/journeys-admin/src/libs/checkConditionalRedirect/checkConditionalRedirect.ts`:
- Around line 39-42: The redirect check uses the raw query-string encoded
`redirect` value (assigned to requestedRedirect from resolvedUrl) which makes
the `/users/verify` escape hatch fail when query order/encoding differs; instead
parse the redirect into a URL and use its pathname for comparisons. Update the
logic that builds and compares `encodedRedirect`/startsWith checks (the blocks
around the requestedRedirect usage and the `/users/verify${encodedRedirect}`
comparison, including the earlier 50-58 and later 80-81 checks) to derive `const
redirectPath = new URL(requestedRedirect, 'https://admin.nextstep.is').pathname`
(or equivalent) and use `redirectPath` (or pathname-based startsWith) when
matching `/users/verify` and related route checks.
🪄 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: 647c3459-e355-4e4f-9faa-e13d2c52f85c

📥 Commits

Reviewing files that changed from the base of the PR and between 4936076 and 495fb40.

📒 Files selected for processing (2)
  • apps/journeys-admin/src/libs/checkConditionalRedirect/checkConditionalRedirect.spec.tsx
  • apps/journeys-admin/src/libs/checkConditionalRedirect/checkConditionalRedirect.ts
✅ Files skipped from review due to trivial changes (1)
  • apps/journeys-admin/src/libs/checkConditionalRedirect/checkConditionalRedirect.spec.tsx

@stage-branch-merger
Copy link
Copy Markdown
Contributor

Merge conflict attempting to merge this into stage. Please fix manually.

@csiyang csiyang requested a review from mikeallisonJS April 8, 2026 02:19
@github-actions github-actions Bot temporarily deployed to Preview - journeys-admin April 8, 2026 02:20 Inactive
@stage-branch-merger
Copy link
Copy Markdown
Contributor

Merge conflict attempting to merge this into stage. Please fix manually.

@github-actions github-actions Bot temporarily deployed to Preview - journeys-admin April 8, 2026 02:25 Inactive
@csiyang csiyang added this pull request to the merge queue Apr 8, 2026
Merged via the queue into main with commit 9f0f429 Apr 8, 2026
20 checks passed
@csiyang csiyang deleted the siyangcao/nes-1525-email-verification-redirects-to-dashboard-instead-of branch April 8, 2026 03:03
tanflem pushed a commit that referenced this pull request Apr 13, 2026
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.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