Skip to content

fix(frontend): allow mock=true demo URLs through workspace auth guard#3093

Open
64johnlee wants to merge 1 commit into
bytedance:mainfrom
64johnlee:fix/react-duplicate-message-keys
Open

fix(frontend): allow mock=true demo URLs through workspace auth guard#3093
64johnlee wants to merge 1 commit into
bytedance:mainfrom
64johnlee:fix/react-duplicate-message-keys

Conversation

@64johnlee
Copy link
Copy Markdown
Contributor

Problem

Closes #3000

Public Case Studies landing page links to mock demo chat URLs such as:

/workspace/chats/7cfa5f8f-a2f8-47ad-acbd-da7137baf990?mock=true

The workspace/layout.tsx server component runs a full auth check for every /workspace/* route and redirects unauthenticated visitors to /login before the page can read ?mock=true. This makes the public demos completely unreachable for anonymous users.

Root Cause

Next.js App Router layouts receive children and params but not searchParams, so the layout cannot read ?mock=true directly to skip the auth redirect.

Fix

Two small files changed:

src/middleware.ts (new) — Next.js middleware that runs before the layout. When ?mock=true is present, it clones the request headers and injects x-mock: true, which server components can read via headers() from next/headers.

src/app/workspace/layout.tsx — Added an early-return path before getServerSideUser():

const headersList = await headers();
if (headersList.get("x-mock") === "true") {
  return <WorkspaceContent>{children}</WorkspaceContent>;
}

The chat page already handles mock mode via useThreadChat().isMock (switching to the read-only mock API client). This change simply lets the request reach the page.

Validation

  • pnpm typecheck — clean
  • pnpm lint — clean
  • Normal authenticated workspace routes are completely unaffected (middleware is a no-op when mock param is absent)

The workspace layout server component redirects all unauthenticated
visitors to /login before the page can read ?mock=true, making the
public Case Studies demo links unusable for anonymous users.

A new Next.js middleware propagates ?mock=true into an x-mock request
header so the server-side workspace layout can detect mock requests and
serve WorkspaceContent directly without the auth redirect.  The page
already uses useThreadChat().isMock to switch to the read-only mock API
client; this change simply lets the request reach the page.

Closes bytedance#3000

Co-Authored-By: Claude Sonnet 4.6 <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.

Public Case Studies links redirect to login even with mock=true

1 participant