Can I share client API routes across subdomains?
I have a monorepo setup and trying to use one app's API routes from another app. (For example, calling localhost:3000's routes from localhost:3001. In production, it will be calling app.domain.com's routes from admin.domain.com) I faced the cors error as expected in local development. Tried to fix it by adding
mode: "no-cors"
:
But it didn't work and still getting this error:
12 Replies
remove
no-cors
. it should work just make sure to configure your server for cors. Make sure not to use wild card origins and to enabled credentialsWhen I remove
no-cors
, I get the cors error as below:
My server config is as below. Do I need to add or change anything to make it work?
@bekacru could you please check this? : )share your cors config
you mean
crossSubDomainCookies
? If you mean other cors config, could you please tell me how to configure?what framework are you using?
I'm using nextjs 15
@bekacru It worked after manually modifying the header of GET and POST route handlers. But for social sign-ins, it still redirects to the original baseURL (for example, I call the localhost:3001's API route from localhost:3002 and after sign-in is successful, it redirects to the localhost:3001 instead of localhost:3002). I get that it's the expected behavior. But is there any way to change it? I tried setting callbackURL like below but doesn't work.
this should work. Make sure it's in a trusted origin.
my auth server config already has trustedOrigins configured
so you have 2 differnt nextjs projects?
yes, my plan is to use one app's auth routes from another app
im not sure why this is working. It should redirect back to callback url unless some error happens. In which case, you should specefic
errorCallbackURL
instead.I see, thanks for your time! 🙌