Skip to content

feat(proxy): add x-current-path header for admin routing and update P… - #2149

Merged
igorosip0v merged 2 commits into
mainfrom
fix-auth0-profile-fetching
Jul 24, 2026
Merged

feat(proxy): add x-current-path header for admin routing and update P…#2149
igorosip0v merged 2 commits into
mainfrom
fix-auth0-profile-fetching

Conversation

@igorosip0v

Copy link
Copy Markdown
Contributor

PR Type

  • Regular Task
  • Bug Fix
  • QA Tests

Description

This PR prevents admin pages from periodically requesting Auth0 /api/auth/profile and receiving 401 responses. Admin pages use separate authentication, but the global PostHog provider previously mounted Auth0 useUser() for every route.

  • Mounts Auth0 user identification only outside /admin.
  • Keeps the PostHog provider available and resets its identity on admin pages.
  • Passes the resolved route path through the proxy to handle dashboard-host root rewrites.
  • Keeps existing admin authorization checks unchanged.
  • Adds regression coverage for admin routes, root rewrites, client navigation, and proxy path forwarding.

Tested with:

  • pnpm exec jest tests/unit/root-posthog-provider.test.tsx tests/unit/proxy-auth-origin.test.ts --runInBand — 29 tests passed.
  • Prettier check for all changed files.

Checklist

  • I have self-reviewed this PR.
  • I have left comments in the code for clarity.
  • I have added necessary unit tests.
  • I have updated the documentation as needed.

…ostHog provider logic

- Introduced x-current-path header in proxy responses for better path tracking.
- Updated RootLayout to determine if the request is for an admin page based on the x-current-path header.
- Enhanced WithPostHogIdentifier to conditionally load Auth0 user based on admin request status.
- Added unit tests to verify the new behavior for admin page handling and PostHog integration.
@igorosip0v
igorosip0v requested a review from Takaros999 July 23, 2026 14:20
@igorosip0v igorosip0v self-assigned this Jul 23, 2026
// from `web/proxy.ts` to framework and page scripts.
await headers();
const requestHeaders = await headers();
const currentPath = requestHeaders.get("x-current-path");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

im curious if in nextjs using this header is the most reliable way for reading the path

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

AFAIK it was an issue some time and still is.

  1. Issue
  2. Next.js docs recommend passing information from proxy this way

Comment thread web/scenes/Root/layout/index.tsx Outdated

<Auth0Provider>
<WithPostHogIdentifier>
<WithPostHogIdentifier isAdminRequest={isAdminRequest}>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i found the naming very confusing. Conceptually we're trying to disable the posthog provider for admin routes.

I feel like we should either have a disable=boolean prop in posthog provider or in this file hide conditionally based on the admin routes
eg.

      <WithPostHogIdentifier disable={isAdminRequest}>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated

…dentification prop

- Replaced isAdminRequest with disableUserIdentification in WithPostHogIdentifier for clearer intent.
- Adjusted RootLayout to reflect the new prop and updated related logic.
- Modified unit tests to ensure compatibility with the new prop structure.
@igorosip0v
igorosip0v merged commit 093180a into main Jul 24, 2026
13 checks passed
@igorosip0v
igorosip0v deleted the fix-auth0-profile-fetching branch July 24, 2026 11:47
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.

2 participants