Skip to content

How to use Prisma Middleware? #3339

Answered by beerose
Kiodok asked this question in Q&A
May 7, 2022 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

Hey @Kiodok!

Just to confirm — client.$use(fieldEncryptionMiddleware()) (where client is the client defined in db/index.ts) doesn't work? I know that some people successfully added a middleware with something like this:

import { enhancePrisma } from "blitz"
import { PrismaClient } from "@prisma/client"

const EnhancedPrisma = enhancePrisma(PrismaClient)
const prisma = new EnhancedPrisma()

prisma.$use(async (params, next) => {
  // Apply any middleware for prisma here.
  console.log(params.action, params.model)
  const result = await next(params)

  return result
})

export * from "@prisma/client"
export default prisma

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@Kiodok
Comment options

@Kiodok
Comment options

Answer selected by Kiodok
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants