Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read property 'includes' of undefined in prisma adapter with credentials provider #1692

Closed
5 tasks
sunrunner4kr-simon opened this issue Apr 11, 2021 · 5 comments · Fixed by #1694
Closed
5 tasks
Labels
bug Something isn't working

Comments

@sunrunner4kr-simon
Copy link

sunrunner4kr-simon commented Apr 11, 2021

Hoping someone can help me.
I had success getting the google provider authentication working with a prisma adapter implementation.
However, I'm having trouble getting the credentials provider to work, and also had the same error response when trying with email.

I get the following error when using Credentials or email

[next-auth][error][callback_oauth_error]
https://next-auth.js.org/errors#callback_oauth_error TypeError: Cannot read property 'includes' of undefined
at Object. (D:\Web\StoreApp\nextjs-store\node_modules\next-auth\dist\server\lib\oauth\pkce-handler.js:54:32)
at Generator.next ()
at asyncGeneratorStep (D:\Web\StoreApp\nextjs-store\node_modules\next-auth\dist\server\lib\oauth\pkce-handler.js:32:103)
at _next (D:\Web\StoreApp\nextjs-store\node_modules\next-auth\dist\server\lib\oauth\pkce-handler.js:34:194)
at D:\Web\StoreApp\nextjs-store\node_modules\next-auth\dist\server\lib\oauth\pkce-handler.js:34:364
at new Promise ()
at Object. (D:\Web\StoreApp\nextjs-store\node_modules\next-auth\dist\server\lib\oauth\pkce-handler.js:34:97)
at Object.handleCallback (D:\Web\StoreApp\nextjs-store\node_modules\next-auth\dist\server\lib\oauth\pkce-handler.js:41:26)
at D:\Web\StoreApp\nextjs-store\node_modules\next-auth\dist\server\index.js:256:32
at Generator.next ()
at asyncGeneratorStep (D:\Web\StoreApp\nextjs-store\node_modules\next-auth\dist\server\index.js:52:103)
at _next (D:\Web\StoreApp\nextjs-store\node_modules\next-auth\dist\server\index.js:54:194)
at runMicrotasks ()
at processTicksAndRejections (node:internal/process/task_queues:94:5)

Here is my [...nextauth].js

import NextAuth from "next-auth";
import Providers from "next-auth/providers";
import Adapters from "next-auth/adapters";
import { PrismaClient } from "@prisma/client";

const prisma = new PrismaClient();

export default NextAuth({
  providers: [
    Providers.Credentials({
      // The name to display on the sign in form (e.g. 'Sign in with...')
      name: "Credentials",
      // The credentials is used to generate a suitable form on the sign in page.
      // You can specify whatever fields you are expecting to be submitted.
      // e.g. domain, username, password, 2FA token, etc.
      credentials: {
        username: { label: "Username", type: "text", placeholder: "jsmith" },
        password: { label: "Password", type: "password" },
      },
      async authorize(credentials) {
        // Add logic here to look up the user from the credentials supplied
        const user = await prisma.user.findUnique({
          where: {
            username: credentials.username,
            password: credentials.password,
          },
        });

        if (user) {
          // Any object returned will be saved in `user` property of the JWT
          return user;
        } else {
          // If you return null or false then the credentials will be rejected
          return null;
          // You can also Reject this callback with an Error or with a URL:
          // throw new Error('error message') // Redirect to error page
          // throw '/path/to/redirect'        // Redirect to a URL
        }
      },
    }),
  ],
  adapter: Adapters.Prisma.Adapter({ prisma }),
});

I can give provide access to the repo for anyone that's willing to have a look.

https://github.com/sunrunner4kr-simon/StoreApp

Thanks in advance!

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
@sunrunner4kr-simon sunrunner4kr-simon added the question Ask how to do something or how something works label Apr 11, 2021
@balazsorban44
Copy link
Member

balazsorban44 commented Apr 11, 2021

Could you verify which version of next-auth are you using? We had some trouble lately that this problem probably originates from. (#1691, #1687, #1684)... 😬

cc @fxamauri

@balazsorban44
Copy link
Member

@sunrunner4kr-simon I could verify/identify the problem, and I REALLY hope it is finally fixed... Checked it locally with credentials and OAuth providers and looked good, Tell me if you experience it otherwise!

@balazsorban44 balazsorban44 added bug Something isn't working and removed question Ask how to do something or how something works labels Apr 11, 2021
@github-actions
Copy link

🎉 This issue has been resolved in version 3.14.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

@sunrunner4kr-simon
Copy link
Author

Thank you @balazsorban44 as always!!

@AL1L AL1L mentioned this issue Apr 13, 2021
5 tasks
@github-actions
Copy link

🎉 This issue has been resolved in version 4.0.0-next.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants