ory / integrations

Apache License 2.0
19 stars 24 forks source link

Next.js basePath handling #45

Open RokoTechnology opened 1 year ago

RokoTechnology commented 1 year ago

I am running OpenFAAS based setup with multiple servers on different sub paths of same domain - mydomain.com/function/app1, mydomain.com/function/app2 etc.

Now i'm trying to set up a Next + Ory app at mydomain.com/function/nextapp

I am using Next.js 12 with @ory/client 1.1.4 and @ory/integrations 1.1.0

I have a basePath: '/function/nextapp' in my next.config.js because I need the ory login pages to live on mydomain.com/function/nextapp/api/.ory/ui/login instead of mydomain.com/api/.ory/ui/login

Unfortunately, no matter what I try, I always end up being redirected to mydomain.com/api/.ory/ui/login?flow=...

Looks like the currently suggested Next + Ory setup ignores the next.config.js basePath and it is not possible to override it manually either. Looks like the FrontendApi ignores edgeConfig and always redirects to the root relative basePath /api/.ory/ui/login

RokoTechnology commented 1 year ago

actually, i think the root cause is not in the FrontendApi but in the @ory/integrations/next-edge here https://github.com/ory/integrations/blob/84858eafd718cc28682ca4cc2d713e86b0b36de8/src/next-edge/index.ts#L178

RokoTechnology commented 1 year ago

i made a PR which should resolve my issue. you could pass appBasePath: myNextConfig.basePath to the createApiHandler