Skip to content

Instantly share code, notes, and snippets.

@xixixao
Created January 20, 2024 07:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xixixao/f8f401d1a0d51bd534fbe00875330c97 to your computer and use it in GitHub Desktop.
Save xixixao/f8f401d1a0d51bd534fbe00875330c97 to your computer and use it in GitHub Desktop.
issue getting rewrites and clerk work

We're trying to use vercel rewrites to serve multiple projects under different paths on the same domain. The one I'm working on is using Next.js 14.

Right now I'm using dev clerk instance, but I can't get it to work.

I think the issue is related to this one: clerk/javascript#1740

I am getting these errors:

 authenticateRequest state is interstitial, {
    "status": "interstitial",
    "reason": "cross-origin-referrer",
    "message": "",
    "frontendApi": "proper-whippet-77.clerk.accounts.dev",
    "publishableKey": "pk_test_cHJvcGVyLXdoaXBwZXQtNzcuY2xlcmsuYWNjb3VudHMuZGV2JA",
    "isSatellite": false,
    "domain": "",
    "proxyUrl": "",
    "signInUrl": "",
    "isSignedIn": false,
    "isInterstitial": true,
    "isUnknown": false,
    "token": null
  }

I turned on debug in middleware.ts, and got this:

  URL debug, {
    "url": "https://saas-starter-rouge.vercel.app/saas-starter",
    "method": "GET",
    "headers": "{\"accept\":\"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7\",\"accept-encoding\":\"gzip, deflate, br\",\"accept-language\":\"en-US,en;q=0.9\",\"connection\":\"Keep-Alive\",\"content-length\":\"2219\",\"cookie\":\"__client_uat=1705733473; __session=<redacted>; __clerk_db_jwt=<redacted>\",\"dnt\":\"1\",\"forwarded\":\"for=73.162.199.83;host=saas-starter-rouge.vercel.app;proto=https\",\"host\":\"saas-starter-rouge.vercel.app\",\"referer\":\"https://labs.convex.dev/saas-starter\",\"sec-ch-ua\":\"\\\"Not_A Brand\\\";v=\\\"8\\\", \\\"Chromium\\\";v=\\\"120\\\"\",\"sec-ch-ua-mobile\":\"?0\",\"sec-ch-ua-platform\":\"\\\"macOS\\\"\",\"sec-fetch-dest\":\"document\",\"sec-fetch-mode\":\"navigate\",\"sec-fetch-site\":\"same-origin\",\"upgrade-insecure-requests\":\"1\",\"user-agent\":\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36\",\"x-forwarded-for\":\"73.162.199.83\",\"x-forwarded-host\":\"saas-starter-rouge.vercel.app\",\"x-forwarded-proto\":\"https\",\"x-real-ip\":\"73.162.199.83\",\"x-vercel-deployment-url\":\"saas-starter-9ndg62v1o-xixixao.vercel.app\",\"x-vercel-edge-region\":\"sfo1\",\"x-vercel-id\":\"sfo1:sfo1::6bq7h-1705736081903-6d2469503052\",\"x-vercel-ip-city\":\"San%20Francisco\",\"x-vercel-ip-country\":\"US\",\"x-vercel-ip-country-region\":\"CA\",\"x-vercel-ip-latitude\":\"37.7506\",\"x-vercel-ip-longitude\":\"-122.4121\",\"x-vercel-ip-timezone\":\"America/Los_Angeles\",\"x-vercel-proxied-for\":\"73.162.199.83\"}",
    "nextUrl": "https://saas-starter-rouge.vercel.app/saas-starter",
    "clerkUrl": "https://saas-starter-rouge.vercel.app/saas-starter"
  }

and I do see the mentioned forwarded headers there. Do I need to strip those somehow? Or use some config? The options on middleware are not super well documented, but it doesn't seem like proxyUrl or authorizedParties would help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment