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
- Fastify Next.js example which does not work: https://github.com/neophob/nextjs-fastify-auth
- Next.js only example which does work: https://github.com/neophob/nextjs-auth
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:
- Created 3 years ago
- Comments:21 (21 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Not exactly, we would like to include this feature in the plugin so it doesn’t have to be done in user code.
The user-land fix works for me! Thanks again!