1

I'm using Clerk for authentication in a next.js application with the help of Prisma as an ORM. I know how to manage post model by using authorId for example, but I have problems with many-to-many, enum an one-to-one relations.

I want my user managed by Clerk and I have Product model in my prisma file. Each user can have multiple products and each product can belong to multiple users.

How can I implement this when my User model is not in my prisma file and is managed from an external service?

How can I implement this for enum section and preferences?

model Post {
  id           String        @id @default(cuid())
  title        String
  content      String?       @db.VarChar(14000)
  isPublishded Boolean       @default(false)
  createdAt    DateTime      @default(now())
  updatedAt    DateTime      @updatedAt
  postImages   PostImage[]
  categories   Category[]
  keywords     Keyword[]
  comments     PostComment[]
  authorId String

  @@index([authorId])
}

model Product {
  id             String           @id @default(cuid())
  isPublished    Boolean          @default(false)
  productType    ProductType
  name           String?
  productImages  ProductImage[]
  comments       ProductComment[]
  //users          User[]
  Manufacturer   Manufacturer?    @relation(fields: [manufacturerId], references: [id])
  manufacturerId String?
  Info           Info?            @relation(fields: [infoId], references: [id])
  infoId         String?
  productKeyword ProductKeyword[]

model Prefrences {
  id         String  @id @default(cuid())
  newsletter Boolean
  User       User?
}

enum Role {
  Basic
  Admin
}

The main problem is that there is no User model in my prisma file. I know it's possible to sync clerk with my database, but I want my users to be managed by clerk.

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
javad
  • 13
  • 4

0 Answers0