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.

NextAuth provider not working with custom nextjs pageExtensions

See original GitHub issue

Describe the bug I’m using Relay which generates a __generated__ folder inside my pages folder, and that’s not allowed by Next(it just accept react components inside the pages folder). So, I added to next.config.js the config pageExtensions: ['page.js'] and rename all my pages/ files to the .page.js extension. Now, he’ll no longer consider files without this extension as a React component.

The problem is: my nextAuth app provider(the one inside _app file) is printing an error in every single page that I enter, that’s why he’s breaking because this custom extension. The errors are:

GET http://localhost:3000/api/auth/session 404 (Not Found)

[next-auth][error][client_fetch_error] https://next-auth.js.org/errors#client_fetch_error /api/auth/session SyntaxError: Unexpected token < in JSON at position 0

POST http://localhost:3000/api/auth/_log 404 (Not Found)

Steps to reproduce

  • Create a next app with nextAuth and add the nexAuth provider in the _app file.
  • Create a next.config.js file and add the pageExtensions: ['page.js'] config
  • Rename all your ´/page´ files to the .page.js extension
  • Now you should get a few errors on your console

The repo I’m having this issue is: https://github.com/joao-pedrozo/reviewanything/tree/master/packages/frontend/src/pages

Expected behavior I think that should automatically identify my next.config.js file and adapt to the provider work as expected.

Screenshots or error logs GET http://localhost:3000/api/auth/session 404 (Not Found)

[next-auth][error][client_fetch_error] https://next-auth.js.org/errors#client_fetch_error /api/auth/session SyntaxError: Unexpected token < in JSON at position 0

POST http://localhost:3000/api/auth/_log 404 (Not Found)

Additional context Add any other context about the problem here.

Feedback Documentation refers to searching through online documentation, code comments and issue history. The example project refers to next-auth-example.

  • Found the documentation helpful
  • Found documentation but was incomplete
  • Could not find relevant documentation
  • Found the example project helpful
  • Did not find the example project helpful

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
muftisamiullahcommented, Aug 27, 2021

Im not evenu using custom page extensions but im still getting this issue, im not able to find whats causing the issue,

0reactions
kettanaitocommented, Oct 15, 2021

I’m getting the exact error. Deleting .next and re-running didn’t help. It seems like the nested [...nextuath].page.ts routes are not considered pages by Next (not necessarily Next Auth’s issue).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom Page Extensions - next.config.js
Extend the default page extensions used by Next.js when resolving pages in the pages directory.
Read more >
Custom Page not working · Issue #324 · nextauthjs/next-auth
I checked it out and got it working after a couple of changes. Next.js an older version that NextAuth.js isn't compatible with –...
Read more >
Pages | NextAuth.js
To add a custom login page, you can use the pages option: ... Configuration: There is a problem with the server configuration.
Read more >
NextAuth with custom Credential Provider Not creating session
I managed to resolve the issue eventually. Something was wrong due to specifying the 'id' and 'name' options for the custom credential ......
Read more >
Putting test files in the pages folder in a Next.js app
The problem is that all the possible ways to fix it assume I somehow ... a pull request to add a link to...
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