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.

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

See original GitHub issue

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.<anonymous> (D:\Web\StoreApp\nextjs-store\node_modules\next-auth\dist\server\lib\oauth\pkce-handler.js:54:32) at Generator.next (<anonymous>) 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 (<anonymous>) at Object.<anonymous> (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 (<anonymous>) 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 (<anonymous>) 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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
github-actions[bot]commented, Apr 23, 2021

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

The release is available on:

Your semantic-release bot 📦🚀

0reactions
sunrunner4kr-simoncommented, Apr 12, 2021

Thank you @balazsorban44 as always!!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Invalid p.account.findUnique() invocation with prisma #3815
Same issue here, I'm using Google Provider with Prisma Adapter. error - unhandledRejection: Error: Invalid `p.account.findUnique()` invocation ...
Read more >
Next-Auth: Cannot read property 'Adapter' of undefined
I get this error when I deploy a nextjs app in vercel.in dev mode every thing works fine but when I deploy my...
Read more >
@next-auth/prisma-adapter - npm
Start using @next-auth/prisma-adapter in your project by running `npm i ... TypeScript icon, indicating that this package has built-in type ...
Read more >
Prisma Client
Prisma Client is an auto-generated, type-safe query builder generated based on the models and attributes of your Prisma schema.
Read more >
Next.js Authentication with NextAuth, tRPC and Prisma ORM
Next Auth offers several providers that we can use but today I'm going to focus on Credentials because there are few resources on...
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