basepath is not working in next-auth #12397
-
base path not work in next-autyh properly |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
in my app i have configured the base path as /basepath in next.config so by this all the api's and url end point will now work with /basepath but every ones issue is with basepath, is not working as expected which we are setting in auth.ts in next-auth, i have found the the work around for this for this we need to follow the below steps i am using Next 15, step 1: set the /basepath in next config by follow the step 1 our app will expect the basepath in all urls and api's {children} </> because of this every on facing the issue to over come this follow the next step step 3: configure the basepath in auth.ts: in auth.ts declath the basePath option as this will make next-auth to expect expect the url's and api as http://localhost:/basepath(from step1)/api/auth/ so as per step 2 to will call the api from client as http://localhost:/basepath(from step1)/api/auth/ and it matches with next-auth base path now http://localhost:/basepath(from step1)/api/auth/ as per step 3 step 4:additional for /api/auth/callback/ if we modify this with our desired basepath we 'll get the error as invalid_redirect_uri as response from our provider itself so if if append our base path and called this like http://localhost:/basepath/api/auth/callback/ for this part perm fix next-auth team need to work on the providers api request handling to set the re_directuri based on config or need to allow some parameters to pass for this api for this there is 2 work around 4.1 we can use redirects or rewrites in next.config for this api /api/auth/callback/ as below 4.2 (if yours is micro service architecture and should not call any of your app url or end point without your base path ) then avoid the any public provider configuration in next-auth configure the provider redirect and login in client side so that we can avoid the calling of this and use credentiasprovider for custom handling 4.2.1 configure the credentialsprovider in auth.ts as input of your desired inputs and write you custom authorise method and saved details in session basePath: "/api/auth", })], 4.2.3 in my case i have used keycloak and i have configured the keycloak and keycloak login redirect is handled in client side by following the 4 th steps we can over the callback api of a provider still that will be called by next-auth http://localhost:/api/auth/callback/ because this api never called these steps working perfectly for me as a production ready code |
Beta Was this translation helpful? Give feedback.
in my app i have configured the base path as /basepath in next.config so by this all the api's and url end point will now work with /basepath but every ones issue is with basepath, is not working as expected which we are setting in auth.ts in next-auth, i have found the the work around for this
for this we need to follow the below steps i am using Next 15,
step 1: set the /basepath in next config
const nextConfig = {
basePath: '/basepath', // this will set the basepath for all contents in /app directory
images: {
loader: 'default',
path: '/basepath/_next/image', // this will append the basepath for the image apis called by next
},
assetPrefix: process.env.NEXT_APP_BASE_URL // this is will…