sladg / nextjs-lambda

Lambda deployments for Nextjs12 & Nextjs13 (standalone). Easy CLI commands to get your standalone Next output to run in AWS Lambda (not @Edge)! Uses CDK in behind and produces code zips importable to Terraform, Serverless, Azure, etc.
MIT License
169 stars 19 forks source link

next-auth login() redirection doesn't work #52

Open adamsh25 opened 1 year ago

adamsh25 commented 1 year ago

Use case: I used the repo below and added next-auth using Cognito provider: https://github.com/plevavas/monorepo https://next-auth.js.org/getting-started/example https://next-auth.js.org/providers/cognito

The redirection to Cognito login does work locally when debugging in vs code

Issue: The redirection to Cognito login does NOT work when deployed with tosladg/nextjs-lambda@v3.20.3

sladg commented 1 year ago

Hey @adamsh25 ! Any chance you might have a logs on your hand? Also, if you say that redirection does not work - do you get some Internal Error? Does not not function at all? Do you get stuck on API route?

adamsh25 commented 1 year ago

Hey @sladg I will need to redeploy this test, I will be able to do so over the weekend. Thank you!

sladg commented 1 year ago

I did replicate the behaviour, tested on Cognito and latest Next-auth. It indeed does not redirect properly. From what I was able to gather around Github, it seems like cookies/headers are not passed properly through Cloudfront, I tried out tweaking Origin Request and Cache policies, but no luck. I wasn't able to find what headers/cookies are used/necessary, it will probably require digging into source code of the next-auth.

Let me know if you find some more info!

khuezy commented 1 year ago

Might be related to: https://github.com/nextauthjs/next-auth/pull/5561

sladg commented 1 year ago

@adamsh25 was there any luck resolving this with newest version of Next-auth?