ReasonJun

Prisma : Next Auth Google provider error 본문

Backend/Prisma

Prisma : Next Auth Google provider error

ReasonJun 2023. 11. 7. 02:41
728x90

 

When :

When implementing login using prisma and nextauth.

Error message :

[next-auth][error][adapter_error_getUserByAccount] 
https://next-auth.js.org/errors#adapter_error_getuserbyaccount 
Invalid `prisma.account.findUnique()` invocation:

 

 

prisma code : 

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider     = "mysql"
  url          = env("DATABASE_URL")
  // Add this
  relationMode = "prisma"
}

model Account {
  id                String  @id @default(cuid())
  userId            String
  type              String
  provider          String
  providerAccountId String
  refresh_token     String? @db.Text
  access_token      String? @db.Text
  expires_at        Int?
  token_type        String?
  scope             String?
  id_token          String? @db.Text
  session_state     String?
  user              User    @relation(fields: [userId], references: [id], onDelete: Cascade)

  @@unique([provider, providerAccountId])
  @@index([userId], map: "Account_userId_fkey")
}

model Session {
  id           String   @id @default(cuid())
  sessionToken String   @unique
  userId       String
  expires      DateTime
  user         User     @relation(fields: [userId], references: [id], onDelete: Cascade)

  @@index([userId], map: "Session_userId_fkey")
}

model User {
  id             String          @id @default(cuid())
  name           String?
  email          String?         @unique
  emailVerified  DateTime?
  active         Boolean         @default(false)
  image          String?
  role           String?
  hashedPassword String?
  userType       UserType        @default(User)
  accounts       Account[]
  sessions       Session[]
  ActivateToken  ActivateToken[]
}

model ActivateToken {
  id    String @id @default(cuid())
  token String @unique

  activatedAt DateTime?
  createdAt   DateTime  @default(now())
  updatedAt   DateTime  @updatedAt

  user   User   @relation(fields: [userId], references: [id])
  userId String

  @@index([userId])
}

enum UserType {
  User
  Admin
  Youtuber
}

model VerificationToken {
  identifier String
  token      String   @unique
  expires    DateTime

  @@unique([identifier, token])
}

 

Solution :  remove 'map: "~~~"'



Why ?

 

In the Prisma schema code you provided, the line @@index([userId], map: "Account_userId_fkey") is defining an index for the "Account" model. Let's break down what this line means:

  1. @@index: This is a Prisma schema decorator that is used to define an index on the database table associated with the "Account" model. Indexes are used to optimize database query performance by allowing faster lookup and retrieval of rows based on the indexed columns.
  2. ([userId], map: "Account_userId_fkey"): This part of the code specifies the index definition. It consists of two components:
    • ([userId]): This is an array of column names on which the index is defined. In this case, the index is defined on the "userId" column of the "Account" model. This means that the database will create an index on the "userId" column, which will improve query performance for operations that involve searching or filtering by the "userId" column.
    • map: "Account_userId_fkey": The map option provides a name for the index. In this case, the index is named "Account_userId_fkey." This name is typically used as a reference when working with the database, and it helps in uniquely identifying the index.

In summary, the @@index decorator in your Prisma schema is creating an index on the "userId" column of the "Account" model to improve query performance when searching or filtering records based on the "userId" value. The name of the index is specified as "Account_userId_fkey."

For this reason, 'findUnique' of the account could not be found.

728x90

'Backend > Prisma' 카테고리의 다른 글

Prisma  (0) 2023.06.22
Comments