next-auth: Providers.Credentials not work

Describe the bug The Providers.Credentials not work.

Steps to reproduce

   Providers.Credentials({
     name: 'Credentials',
     credentials: {
       username: { label: "Username", type: "text", placeholder: "jsmith" },
       password: {  label: "Password", type: "password" }
     },
     async authorize(credentials) {
       const user = { id: 1, name: 'J Smith', email: 'jsmith@example.com' }
 
       if (user) {
         return user
       } else {
         return null
       }
     }
   }),
  • click in signin button on home

Expected behavior Let the project work

Screenshots or error logs

ready - started server on 0.0.0.0:3000, url: http://localhost:3000
info  - Loaded env from /Users/vitor/Documents/projetos/project/.env
event - compiled successfully
event - build page: /
wait  - compiling...
event - compiled successfully
event - build page: /api/auth/[...nextauth]
wait  - compiling...
event - compiled successfully
(node:6567) UnhandledPromiseRejectionWarning: TypeError: (0 , _preactRenderToString.default) is not a function
    at signin (/Users/vitor/Documents/projetos/project/node_modules/next-auth/dist/server/pages/signin.js:46:44)
    at Object.signin (/Users/vitor/Documents/projetos/project/node_modules/next-auth/dist/server/pages/index.js:48:35)
    at /Users/vitor/Documents/projetos/project/node_modules/next-auth/dist/server/index.js:188:29
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (/Users/vitor/Documents/projetos/project/node_modules/next-auth/dist/server/index.js:52:103)
    at _next (/Users/vitor/Documents/projetos/project/node_modules/next-auth/dist/server/index.js:54:194)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:6567) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 8)
(node:6567) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Additional context I created a blank project and followed the documentation, but the code simply doesn’t work 😦

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 4
  • Comments: 19 (6 by maintainers)

Most upvoted comments

Just an FYI, I updated our example repo and pushed a new release https://github.com/nextauthjs/next-auth/releases/tag/v3.11.2 that will use 5.1.14, so anyone installing next-auth@latest, this issue shouldn’t be possible anymore.

FYI: I’ve just released v5.1.14 which reverts back to the previous commonjs behaviour. Regardless of whether the new behaviour is more correct, we shouldn’t do such breaking changes in a patch release on our end. Sorry for the trouble caused by that. It should be all resolved now with v5.1.14 👍

Thank you to everyone involved. I managed to get on with the project here 😃

I can’t reproduce the problem anymore when on preact-render-to-string@5.1.14 🎉
thanks @marvinhagemeister

Thank you @marvinhagemeister and @balazsorban44 for working so quickly to fix this!

ow it worked i thought it stil 5.1.7 but when i use npm ls preact-render-to-string it state 5.1.14. Thanks

So nothing to do in our end then! Thanks so much for those involved that got to this so quickly! 😃

Anyone discovering this, update your packages and make sure that you use at least preact-render-to-string@5.1.14! (check your lock files/node_modules)

See explanation above.

@nk9 they did it in the uncompiled/src version and built the module. You cannot use import statements in certain node versions (yet). Thanks for trying to help out, but I think we are on track here, thanks for the useful info @jtwebb!

So a temporary solution is then to edit package-lock.json to a version probably earlier than 5.1.12.

The final solution might be that we just update our import statement to destructure render, but I still want to know the reason. (@jtwebb if interested, do open a PR with your suggestion, and I’ll process it when I get an answer over from preact-render-to-string)

@balazsorban44 I bet you’re right. The package-lock.json file for this repo has preact-render-to-string resolved to version 5.1.7 and mine was resolved to 5.1.13. I forced mine to be 5.1.7 and it started working.

An easy fix for this is to destructure the render function on the signin page. I just gave it a try and built the project and it fixed the issue.

import { render } from 'preact-render-to-string'

I’ve had the same problem. Made a small repo to reproduce the problem: https://codesandbox.io/s/inspiring-glade-pjbhu