question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

next-auth not working with serverless-nextjs

See original GitHub issue

Describe 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.

Screen Shot 2021-03-08 at 3 56 48 PM

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:closed
  • Created 3 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
jeremygottfriedcommented, Mar 9, 2021

I believe I am using the built-in one:

import Adapters from 'next-auth/adapters'

...
adapter: Adapters.Prisma.Adapter({ prisma })

ERROR [next-auth][error][get_user_by_provider_account_id_error] https://next-auth.js.org/errors#get_user_by_provider_account_id_error PrismaClientInitializationError2 [PrismaClientInitializationError]: Query engine binary for current platform “rhel-openssl-1.0.x” could not be found. This probably happens, because you built Prisma Client on a different platform. (Prisma Client looked in “/tmp/query-engine-rhel-openssl-1.0.x”)

Searched Locations:

You already added the platforms “native”, “rhel-openssl-1.0.x” to the “generator” block in the “schema.prisma” file as described in https://pris.ly/d/client-generator, but something went wrong. That’s suboptimal.

Please create an issue at https://github.com/prisma/prisma-client-js/issues/new at PrismaClientFetcher.request (/var/task/pages/api/auth/[…nextauth].js:151931:15) at processTicksAndRejections (internal/process/task_queues.js:97:5) { clientVersion: ‘2.16.1’ }

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!

1reaction
tranthaison1231commented, Mar 22, 2022

@ThangHuuVu Can you help me check this

Read more comments on GitHub >

github_iconTop Results From Across the Web

Adding Authentication to an existing serverless Next.js App in ...
Believe it or not, this is all that's needed for a basic Google OAuth setup with NextAuth.js! The library includes some basic Login...
Read more >
Errors - NextAuth.js
Errors. This is a list of errors output from NextAuth.js. All errors indicate an unexpected problem, you should not expect to see errors....
Read more >
Next.js Authentication with NextAuth and Serverless Redis
NextAuth is a third-party library for Next.js that helps you integrate different identity providers and databases.
Read more >
Serverless Next.js Component - Serverless Framework: Plugins
This project is a better version of the serverless plugin which focuses on addressing core issues like next 9 support, better development experience,...
Read more >
NextAuth.js vs. Serverless Stack Authentication — A Side-by ...
NextAuth.js is an independent library (not supported by Vercel) with the ... This setup relies on the serverless-next.js project and it's ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found