next-auth not working with serverless-nextjs
See original GitHub issueDescribe the bug
I deployed my app to Cloudfront, S3, and AWS Lambda Edge using serverless-nextjs
component offered by serverless.com.
I am getting a 503 error with next-auth when I try to redirect to /api/auth/signin
. I also get the same error if I try to load the signin page directly without a redirect.
The Lambda function associated with the CloudFront distribution is invalid or doesn’t have the required permissions. We can’t connect to the server for this app or website at this time. There might be too much traffic or a configuration error. Try again later, or contact the app or website owner. If you provide content to customers through CloudFront, you can find steps to troubleshoot and help prevent this error by reviewing the CloudFront documentation.
Code:
export async function getServerSideProps(context) {
const session = await getSession(context);
if (!session) {
return {
redirect: {
destination: '/api/auth/signin',
permanent: false,
},
}
}
...
}
Serverless.yml:
myNextApp:
org: myOrg
stage: prod
component: "@sls-next/serverless-component@1.18.0" # it is recommended you pin the latest stable version of serverless-next.js
inputs:
bucketName: myApp-nextjs
region: us-east-1
name: myApp
Actual behavior
Next-auth api endpoints are not working.
Expected behavior
I expected the app to work the same way it does locally. I redirect to a signin page generated by next-auth when the user is not logged in.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (1 by maintainers)
I believe I am using the built-in one:
I have tried many different solutions, talked about here:
I’m going to reopen this issue in prisma and serverless-next.js because it seems to be more of an issue on their end, but if you have any ideas how to solve I would be very greatful!
@ThangHuuVu Can you help me check this