Using Netlify dev locally as I wish to test my serverless functions locally.
Integrated next-auth recently and running into this issue.
On production all is fine in the world. Serverless functions work, next-auth works, all good.
In my .env.local file I use
NEXTAUTH_URL=http://localhost:8888
However doing so means the next-auth callback does not work. Testing a test login gets me a
“Function not found…” error, and in the netlify dev logs:
Warning: Missing form submission function handler
Request from ::1: POST /api/auth/callback/credentials/index.html
A workaround is to swap the NEXT_URL to
NEXTAUTH_URL=http://localhost:3000
This works but it basically means after login it’s swapping me to port 3000 where my serverless functions wont work locally. This isnt ideal and I would imagine if there is functionality then intertwining serverless functions and next-auth this will become a headache to test locally.
I have tried another workaround in my Netlify.toml file to attempt to redirect the /api/ function next-auth uses with:
[dev]
command = "npm run dev"
port = 8888
publish = "out"
targetPort = 3000
[[redirects]]
from = "/api/*"
to = "http://localhost:3000/api/:splat"
status = 200
force = true
This worked locally where I was then able to use port 8888 for everything (serverless functions and next-auth all worked) but this borked production and for some reason when I go to https://www.mysite.com/api/auth/signin I get a HTTP Error 505 (I had hoped this toml redirect would only work on local since I used [dev] but perhaps I’m getting something wrong there.
Really I would just love this to work locally and on production.
Any ideas how I could get this to work?