feat: add PGP encryption utilities and apply automatic decryption to user schema

Introduced centralized PGP encryption utilities and updated the `users` schema to enable automatic decryption for sensitive fields like `email` and `twoFactorSecret`.
This commit is contained in:
Mathis HERRIOT
2026-01-08 17:13:43 +01:00
parent 399bdab86c
commit 702868dec2
2 changed files with 7 additions and 8 deletions

View File

@@ -1,6 +1,6 @@
import { SQL, sql } from "drizzle-orm";
import {
boolean,
customType,
index,
pgEnum,
pgTable,
@@ -8,13 +8,7 @@ import {
uuid,
varchar,
} from "drizzle-orm/pg-core";
// Type personnalisé pour les données chiffrées PGP (stockées en bytea dans Postgres)
const pgpEncrypted = customType<{ data: string; driverData: string }>({
dataType() {
return "bytea";
},
});
import { pgpEncrypted, withAutomaticPgpDecrypt } from "./pgp";
export const userStatus = pgEnum("user_status", [
"active",
@@ -65,5 +59,9 @@ export const users = pgTable(
}),
);
// Application du déchiffrement automatique pour les colonnes PGP
withAutomaticPgpDecrypt(users.email);
withAutomaticPgpDecrypt(users.twoFactorSecret);
export type UserInDb = typeof users.$inferSelect;
export type NewUserInDb = typeof users.$inferInsert;