Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

[next-auth][error][adapter_error_getUserByAccount]; Cannot read properties of undefined (reading 'findUnique')

I am making a sign up page with 3 providers (Twitter, Facebook and Instagram) using next-auth and prisma with mongoDB. The issue appears when I try to sign up with any of the providers. Here is my nextauth.js file.

import NextAuth from "next-auth"

import { PrismaAdapter } from "@next-auth/prisma-adapter"
import { PrismaClient } from '@prisma/client';

import InstagramProvider from "next-auth/providers/instagram";
import TwitterProvider from "next-auth/providers/twitter";
import FacebookProvider from "next-auth/providers/facebook";

const prisma = new PrismaClient();


export default NextAuth({
  adapter: PrismaAdapter(prisma),
  
  providers: [
    InstagramProvider({
      clientId: process.env.INSTAGRAM_CLIENT_ID,
      clientSecret: process.env.INSTAGRAM_CLIENT_SECRET
    }),
    TwitterProvider({
      clientId: process.env.TWITTER_CLIENT_ID,
      clientSecret: process.env.TWITTER_CLIENT_SECRET,
      version: "2.0",
    }),
    FacebookProvider({
      clientId: process.env.FACEBOOK_CLIENT_ID,
      clientSecret: process.env.FACEBOOK_CLIENT_SECRET
    }),

  ],
  session: {
    strategy: 'jwt',
  },
  
});

I have tried to reinstall all the dependencies, because I don't see what else could be the problem. At first I thought it was the dependencies so I reinstall all the dependencies.

like image 991
Velislav Dimitrov Avatar asked Oct 18 '25 00:10

Velislav Dimitrov


2 Answers

The problem is in your adapter in the [nextauth].js file or wherever you are declaring the prisma instance.

Check out those similar discussions:

  • https://github.com/nextauthjs/next-auth/discussions/4152
  • Integrating Prisma Adapter with Next Auth - Unexpected token 'export'
like image 50
InfiniteScope Avatar answered Oct 19 '25 18:10

InfiniteScope


Adding @map("provider_account_id") to the providerAccountId in the Account model in the schema.prisma file worked for me.

source: bassem97's solution

like image 37
Sipher Avatar answered Oct 19 '25 18:10

Sipher