-
Notifications
You must be signed in to change notification settings - Fork 45
Fix wholesale sign-in redirect loop and nested anchor markup #200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
damianlegawiec
merged 12 commits into
main
from
claude/wholesale-pricing-redirect-loop-xg9pzk
Jul 28, 2026
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
dadcbc1
Fix wholesale sign-in redirect loop and nested-link hydration error
claude 8fe6e67
Add wholesale portal E2E suite
claude 375b688
Harden redirect handling and address review findings
claude 2fa07bf
Stop wholesale E2E assertions reading stale route trees
claude 33f2c19
Report why a wholesale application was rejected
claude 50f2fc4
Address review feedback on cart guards and e2e retries
claude abd5adc
Assert the wholesale application's durable outcome
claude b3ce8e2
Wait for hydration before driving wholesale sign-in forms
claude dcf4044
Share one redirect validator across sign-in surfaces
claude e586e5f
Scope the portal's sign-in redirect to wholesale destinations
claude 428fb8f
Revert "Scope the portal's sign-in redirect to wholesale destinations"
claude e8b9801
Drop the wholesale E2E suite from this change
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/app/[country]/[locale]/(wholesale)/wholesale/sign-in/page.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import { redirect } from "next/navigation"; | ||
| import { getCustomer } from "@/lib/data/customer"; | ||
| import { getWholesaleChannel } from "@/lib/data/wholesale"; | ||
| import { safeRedirectPath } from "@/lib/utils/path"; | ||
| import { WholesaleSignInWall } from "../_components/WholesaleSignInWall"; | ||
|
|
||
| interface WholesaleSignInPageProps { | ||
| params: Promise<{ country: string; locale: string }>; | ||
| // Repeated query keys arrive as an array, so accept what Next.js can deliver. | ||
| searchParams: Promise<{ redirect?: string | string[] }>; | ||
| } | ||
|
|
||
| /** | ||
| * Dedicated sign-in destination for the portal. On a `prices_hidden` channel | ||
| * the catalog root renders for guests, so "sign in" affordances can't point | ||
| * there — they'd land right back on the catalog (and, with `?redirect=` | ||
| * re-appended on every click, loop forever). This page always shows the | ||
| * sign-in wall (which also links to the apply form) and honours the same | ||
| * `?redirect=` contract; an already-authenticated buyer is bounced into the | ||
| * portal, where the gate resolves their approval state. | ||
| */ | ||
| export default async function WholesaleSignInPage({ | ||
| params, | ||
| searchParams, | ||
| }: WholesaleSignInPageProps) { | ||
| const { country, locale } = await params; | ||
| const { redirect: redirectParam } = await searchParams; | ||
| const basePath = `/${country}/${locale}`; | ||
|
|
||
| const [customer, channel] = await Promise.all([ | ||
| getCustomer(), | ||
| getWholesaleChannel(), | ||
| ]); | ||
|
|
||
| if (customer) { | ||
| redirect(safeRedirectPath(redirectParam, `${basePath}/wholesale`)); | ||
| } | ||
|
|
||
| return ( | ||
| <WholesaleSignInWall | ||
| basePath={basePath} | ||
| storefrontAccess={channel?.storefront_access} | ||
| /> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { wholesaleSignInHref } from "../wholesale"; | ||
|
|
||
| describe("wholesaleSignInHref", () => { | ||
| const basePath = "/us/en"; | ||
|
|
||
| it("points at the dedicated sign-in page", () => { | ||
| expect(wholesaleSignInHref(basePath)).toBe("/us/en/wholesale/sign-in"); | ||
| }); | ||
|
|
||
| it("carries a return target", () => { | ||
| expect( | ||
| wholesaleSignInHref(basePath, "/us/en/wholesale/products/mug?ref=grid"), | ||
| ).toBe( | ||
| "/us/en/wholesale/sign-in?redirect=%2Fus%2Fen%2Fwholesale%2Fproducts%2Fmug%3Fref%3Dgrid", | ||
| ); | ||
| }); | ||
|
|
||
| it("drops a stale redirect instead of nesting it", () => { | ||
| expect( | ||
| wholesaleSignInHref( | ||
| basePath, | ||
| "/us/en/wholesale?redirect=%2Fus%2Fen%2Fwholesale", | ||
| ), | ||
| ).toBe("/us/en/wholesale/sign-in?redirect=%2Fus%2Fen%2Fwholesale"); | ||
| }); | ||
|
|
||
| it.each([ | ||
| "https://example.com/us/en/wholesale", | ||
| "//example.com", | ||
| "/us/en/wholesale/sign-in", | ||
| null, | ||
| ])("omits an unusable return target: %s", (returnTo) => { | ||
| expect(wholesaleSignInHref(basePath, returnTo)).toBe( | ||
| "/us/en/wholesale/sign-in", | ||
| ); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { resolveLocalPath, safeRedirectPath } from "../path"; | ||
|
|
||
| describe("resolveLocalPath", () => { | ||
| it.each([ | ||
| ["/us/en/wholesale", "/us/en/wholesale"], | ||
| [ | ||
| "/us/en/wholesale/products/mug?category_id=3#specs", | ||
| "/us/en/wholesale/products/mug?category_id=3#specs", | ||
| ], | ||
| [["/us/en/wholesale", "/us/en/account"], "/us/en/wholesale"], | ||
| // An encoded path is ordinary data inside a query value. | ||
| [ | ||
| "/us/en/wholesale?redirect=%2Fus%2Fen%2Fwholesale", | ||
| "/us/en/wholesale?redirect=%2Fus%2Fen%2Fwholesale", | ||
| ], | ||
| ])("resolves a same-origin path: %s", (value, expected) => { | ||
| expect(resolveLocalPath(value)).toBe(expected); | ||
| }); | ||
|
|
||
| it.each([ | ||
| "https://example.com/us/en/wholesale", | ||
| "//example.com/us/en/wholesale", | ||
| "/\\example.com/us/en/wholesale", | ||
| "/us/en/wholesale%2f%2fexample.com", | ||
| "us/en/wholesale", | ||
| "//[", | ||
| "", | ||
| ])("rejects a value that is not a local path: %s", (value) => { | ||
| expect(resolveLocalPath(value)).toBeNull(); | ||
| }); | ||
|
|
||
| it.each([null, undefined, []])("rejects %s", (value) => { | ||
| expect(resolveLocalPath(value)).toBeNull(); | ||
| }); | ||
| }); | ||
|
|
||
| describe("safeRedirectPath", () => { | ||
| const fallback = "/us/en/wholesale"; | ||
|
|
||
| it("returns the resolved path when it is local", () => { | ||
| expect(safeRedirectPath("/us/en/wholesale/cart", fallback)).toBe( | ||
| "/us/en/wholesale/cart", | ||
| ); | ||
| }); | ||
|
|
||
| it("returns the fallback when the value points elsewhere", () => { | ||
| expect(safeRedirectPath("https://example.com", fallback)).toBe(fallback); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.