Skip to content

fix: derive API and content base URLs from the app mount prefix (vanity domain /auth/) - #1985

Open
tomski747 wants to merge 6 commits into
mainfrom
feat/auth-prefix-relative-paths
Open

tomski747 wants to merge 6 commits into
mainfrom
feat/auth-prefix-relative-paths

Conversation

@tomski747

@tomski747 tomski747 commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Problem

On a vanity domain the app is served under an /auth/ prefix: https://vanity-domain.descope.team/auth/login/<pid>. A customer demo HAR showed two classes of wrong URLs:

  1. Everything the app computes from the bare window.location.origin 404s: POST /v1/flow/validate-domain, GET /pages/<pid>/v2-beta/config.json, theme.json. Because config.json fails, the web component then requests @descope/web-components-ui@undefined from the CDNs (downstream symptom).
  2. env.js and static/* are requested at /login/... rather than /auth/login/.... They only work today because the edge also serves /login/* on vanity hosts, which we want to retire.

Regular custom domains served at the root (https://host/login/<pid>) must keep working.

Fix

Runtime URLs (commit 1). New helper src/shared/basePath.ts: getBasePath(pathname) returns everything before the /login segment (package.json homepage), so "" for root mounts, /auth for the vanity case, and any other nested prefix. Nothing is hardcoded to auth. Applied in App.tsx (REACT_APP_USE_ORIGIN_BASE_URL base), index.tsx (origin-relative REACT_APP_CONTENT_BASE_URL; absolute values untouched) and Welcome.tsx (example URL). Unit tests cover no prefix, /auth, nested prefix, trailing slash / missing project id, no /login segment, and the window.location default.

Build-time asset URLs (commits 2-3). .env.production sets PUBLIC_URL=. so the production build emits ./env.js, ./static/js/..., ./static/css/... and webpack public path ./. Relative paths alone are not enough: on /auth/login (no project id) ./env.js resolves to /auth/env.js, and a Vercel trailing-slash redirect cannot help because the edge strips /auth before Vercel sees the request (observed: /auth/login/<pid>/ -> 308 to /login/<pid>). So public/index.html now has an inline bootstrap that sets <base href> to everything up to and including the login segment of the pathname. Assets then resolve to /login/env.js and /login/static/... on root domains and /auth/login/env.js and /auth/login/static/... on the vanity host, for /login, /login/<pid>, /login/<pid>/, /auth/login/<pid> and nested prefixes alike. The Descope edge strips /auth and routes /login* to Vercel, where the existing /login/:path* -> /:path* rewrite serves the files, so no edge change is needed. Dev is unchanged (CRA ignores a relative PUBLIC_URL in development and falls back to homepage, i.e. /login).

Verified in Chrome against the production build served behind a local edge simulator (strips the prefix, applies the /login rewrite): for each of /auth/login/<pid>, /auth/login/<pid>/, /auth/login, /login, /login/<pid>, /a/b/login/<pid>/, env.js, main.js and main.css load from <prefix>/login/... with 200.

Checked and left alone

  • middleware.ts fetches /.well-known/project-configuration/<pid> from MIDDLEWARE_DESCOPE_BASE_URL, not the request origin, and reads the project id from the last path segment, so the prefix does not affect it.
  • The saml-config/sso-config redirect in App.tsx preserves window.location.pathname, so the prefix survives.
  • The existing /login/:path* rewrite is kept; Vercel-origin requests are unchanged.

Infra to confirm

  • Nothing requests bare /login/* on the vanity host anymore, so that edge route can be retired for this app once this is deployed.

Verification

  • yarn test: 4 suites, 75 tests pass.
  • eslint src middleware.ts --max-warnings 0 and prettier: clean. yarn lint:ci has one pre-existing parsing error in config-overrides.js (not in tsconfig.json), unrelated.
  • yarn build compiles successfully; the built head contains the base bootstrap and relative asset references.

🤖 Generated with Claude Code

@shuni-bot

shuni-bot Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

🐕 Shuni Review

No new issues found.

🤖 Model: claude-opus-5.5 · Effort: medium


Review scope: Partial incremental re-review

Reviewed new changes (1)
  • src/indexHtml.test.ts
Previously reviewed and unchanged: 7 files.

🐕 Review complete — View session on Shuni Portal 🐾

🤖 Model: claude-opus-5.5 · Effort: medium

@tomski747
tomski747 force-pushed the feat/auth-prefix-relative-paths branch from fb3499c to 82228f5 Compare October 22, 2026 14:56

@shuni-bot shuni-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐕 Shuni review: no new findings. Every changed file in this pull request was reviewed.

The full review summary is in Shuni's sticky review comment on this pull request.

@shuni-bot shuni-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐕 Shuni review: no new findings. Every changed file in this pull request was reviewed.

The full review summary is in Shuni's sticky review comment on this pull request.

@shuni-bot shuni-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐕 Shuni review: 1 inline finding. Every changed file in this pull request was reviewed.

The full review summary is in Shuni's sticky review comment on this pull request.

Comment thread .env.production Resolved

@shuni-bot shuni-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐕 Shuni review: no new findings. Every changed file in this pull request was reviewed.

The full review summary is in Shuni's sticky review comment on this pull request.

@shuni-bot shuni-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐕 Shuni review: 1 inline finding. Every changed file in this pull request was reviewed.

The full review summary is in Shuni's sticky review comment on this pull request.

Comment thread public/index.html Resolved

@shuni-bot shuni-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐕 Shuni review: no new findings. Every changed file in this pull request was reviewed.

The full review summary is in Shuni's sticky review comment on this pull request.

@tomski747
tomski747 requested a review from asafshen October 25, 2026 14:31
tomski747 and others added 5 commits November 19, 2026 14:06
When auth-hosting is served under a path prefix (e.g. a vanity domain at
https://host/auth/login/<pid>), the API base URL and content base URL were
built from the bare window.location.origin, so /v1/flow/validate-domain and
/pages/<pid>/... were requested at the root and 404ed. Derive the prefix from
whatever precedes the /login segment in the pathname and apply it to both.
Root-mounted custom domains keep an empty prefix and behave as before.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…efix

PUBLIC_URL=. for production builds makes index.html reference ./env.js and
./static/... which resolve against the document URL, so /auth/login/<pid>
loads /auth/login/env.js instead of /login/env.js. trailingSlash: false keeps
relative resolution correct by redirecting /login/<pid>/ to /login/<pid>.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
… tag

Relative ./env.js and ./static/... only resolved correctly when the document
path had a segment after /login. On /auth/login (no project id) they resolved
to /auth/env.js, and the Vercel trailing-slash redirect dropped the /auth
prefix because the edge strips it before Vercel. An inline bootstrap now sets
<base href> to everything up to and including the login segment, so assets
resolve to <prefix>/login/... for /login, /login/<pid>/ and /auth/login/<pid>
alike. The trailingSlash setting is no longer needed and is removed.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The asset root is the mount prefix itself, not <prefix>/login: the base tag
now points at everything before the login segment, so ./env.js resolves to
/env.js on root domains and /auth/env.js on a vanity host.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@tomski747
tomski747 force-pushed the feat/auth-prefix-relative-paths branch from 48d9297 to 1cc3e69 Compare November 19, 2026 14:07
@tomski747
tomski747 enabled auto-merge (squash) November 19, 2026 14:07
@tomski747
tomski747 disabled auto-merge November 19, 2026 14:07

@shuni-bot shuni-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐕 Shuni review: 1 inline finding. Every changed file in this pull request was reviewed.

The full review summary is in Shuni's sticky review comment on this pull request.

Comment thread public/index.html Resolved

@shuni-bot shuni-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐕 Shuni review: no new findings. Every changed file in this pull request was reviewed.

The full review summary is in Shuni's sticky review comment on this pull request.

This branch was successfully deployed

1 active (outdated) deployment
Production – auth-hosting-dev-7397648 — 48d92971 Deployed Oct 25, 2026 by vercel[bot]
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