import { PrismaClient } from "@prisma/client";
import { createFieldEncryptionExtension } from "@sebastienrousseau/crypto-prisma";
const prisma = new PrismaClient().$extends(
createFieldEncryptionExtension({
key: process.env.FIELD_ENCRYPTION_KEY!,
encryptedFields: [
{ model: "User", fields: ["email", "phone"] },
],
})
);
Create a Prisma Client Extension that transparently encrypts/decrypts configured model fields.
Writes (
create,createMany,update,updateMany,upsert) seal each configured field in thev2:format, bound to its model and field. Reads (findUnique,findFirst,findManyand theOrThrowvariants) decrypt them and reject with aFieldDecryptionErrorwhen a stored value is not a valid ciphertext for that model and field.