Skip to content

fix: Frontend API proxy example for Next.js #2248

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

brkalow
Copy link
Member

@brkalow brkalow commented May 22, 2025

🔎 Previews:

What does this solve?

  • The proxy middleware example does not work properly as the proxy logic is not executed until clerkMiddleware() authenticates the request. This is unnecessary and causes issues in the handshake flow.

What changed?

The implementation has been improved to guarantee that proxy routes are always checked and handled before the Clerk middleware executes. This execution order is critical because it ensures that requests to the proxy path (__clerk) are correctly intercepted and routed to Clerk's Frontend API before any authentication middleware runs, preventing potential conflicts in request handling.

Checklist

  • I have clicked on "Files changed" and performed a thorough self-review
  • All existing checks pass

@brkalow brkalow requested a review from a team as a code owner May 22, 2025 02:34
Copy link

Hey, here’s your docs preview: https://clerk.com/docs/pr/2248

@brkalow brkalow changed the title fix: fix Frontend API proxy example for Next.js fix: Frontend API proxy example for Next.js May 22, 2025
@brkalow brkalow requested a review from jacekradko May 22, 2025 02:35
Copy link
Member

@alexisintech alexisintech left a comment

Choose a reason for hiding this comment

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

😸💖

Copy link
Member

@royanger royanger left a comment

Choose a reason for hiding this comment

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

It might be worth linking to this from the clerkMiddleware doc. Maybe from

- `proxyUrl?`
- `string`

@royanger
Copy link
Member

Hey @brkalow, I was going to create a linear but with this PR still open, did you want to make the following fix in the warning callout?

If your application already uses a CNAME subdomain that is required for deploying with Clerk, then you must proxy the Frontend API using a different subdomain.

The last part should read '...you must proxy the Frontend API using a path on your domain' or something along those lines.

I can do a separate ticket if you want.

@brkalow
Copy link
Member Author

brkalow commented May 23, 2025

@royanger feel free to push up directly to this branch!

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.

4 participants