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.

Integration with next-auth fails, routing issue

See original GitHub issue

🐛 Bug Report

I want to integrate next-auth with my fastify-nextjs project. This worked until the next.auth library does the login/POST callback - somehow this call does not succeed and just times out. I ported the exact same code to a vanilla Next.js project (using npx create-next-app) and there it works flawlessly!

To Reproduce

Expected behavior

call is terminated correct / callback is called. I quickly added some console log into the plugin to figure out where the code hangs:

    function handler (req, reply) {
      if (callback) {
        return callback(app, req, reply)
      }
      console.log("handle next request", req.params)
      return handleNextRequests(req.raw, reply.raw)
        .then(() => {
          console.log("...handled")
          reply.sent = true
        })
  • when the login POST request is hanging, the handleNextRequests function is running
  • when I cancel the POST request (using postman), then the ...handled console output is visible…

the console shows this output:

{"level":30,"time":1613721952594,"pid":94353,"hostname":"hostname","reqId":29,"req":{"method":"POST","url":"/api/auth/callback/credentials","hostname":"localhost:3333","remoteAddress":"::1","remotePort":55873},"msg":"incoming request"}
handle next request { '*': 'auth/callback/credentials' }
event - build page: /api/auth/[...nextauth]
wait  - compiling...
event - compiled successfully

To summarize, I think the POST call to /api/auth/callback/credentials is either not routed correctly OR the return value is invalid (promise vs. value maybe?)

Your Environment

  • node version: 12 and 14
  • fastify version: 3.12
  • os: Mac

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:21 (21 by maintainers)

github_iconTop GitHub Comments

1reaction
simonebcommented, Mar 3, 2021

Not exactly, we would like to include this feature in the plugin so it doesn’t have to be done in user code.

0reactions
neophobcommented, Mar 10, 2021

The user-land fix works for me! Thanks again!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Errors - NextAuth.js - JS.ORG
This error occurs when the SessionProvider Context has a problem fetching session data. CLIENT_FETCH_ERROR​. If you see CLIENT_FETCH_ERROR make ...
Read more >
Support Next.js 13 `app` directory · Issue #5647 - GitHub
I'm keep getting an error Error: React Context is unavailable in Server Components . "next": "13.0.2", "next-auth": "^4.16.4", "react": ...
Read more >
How to protect routes in Next.js next-auth? - Stack Overflow
The problem with the given example is that I need to check if there is a session on every page that requires authentication...
Read more >
Building an authentication API with NextAuth.js
API routes run on one server during development, and when deployed, are deployed as sever-less functions that run independently of each other.
Read more >
Next.js JWT Authentication with NextAuth and Integration with ...
Let's look at the directory structure. Inside the pages directory under the api routes, you have the logic written for auth in the...
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