Working universal solution for Auth v5 in dockerized Next.js with basePath #12160
Replies: 2 comments 1 reply
-
I follow the step 1 to step 5, and finally it works. Still don't understand why this bug has NOT been fixed. The only problem in above guide is that, in the step 5, the export async function GET(request) {
return await handlers.GET(rewriteRequest(request)) //<=======removed `props` argument
}
export async function POST(request, props) {
return await handlers.POST(rewriteRequest(request)) //<=======removed `props` argument
} |
Beta Was this translation helpful? Give feedback.
-
When implementing the middleware in Step 6, the pathname included the basePath, and it did not work correctly. I resolved this issue by applying the following fix:
With this fix, the application now works properly in environments with a basePath. |
Beta Was this translation helpful? Give feedback.
-
The problem: setting
basePath
in Next.js config completely broke Auth.basePath
in Auth config didn't help as built-in actions (signin, signout) didn't work.AUTH_URL
partially helped but broke other non-auth middleware.After lot's of struggling I've got fully functional solution working both in local dev environment without base path and dockerized prod environment with base path.
AUTH_URL
is not defined!app/api/auth/[...nextauth]/route.js
is complicated to rewriterequest
so that it contains proper host name and base path. Otherwise auth actions do not work or do not properly redirect:Beta Was this translation helpful? Give feedback.
All reactions