diff --git a/backend/src/database/schemas/index.ts b/backend/src/database/schemas/index.ts index 4858b3d..e54a30a 100644 --- a/backend/src/database/schemas/index.ts +++ b/backend/src/database/schemas/index.ts @@ -8,3 +8,4 @@ export * from "./reports"; export * from "./sessions"; export * from "./tags"; export * from "./users"; +export * from "./pgp"; diff --git a/backend/src/database/schemas/users.ts b/backend/src/database/schemas/users.ts index 0254a8e..9190acd 100644 --- a/backend/src/database/schemas/users.ts +++ b/backend/src/database/schemas/users.ts @@ -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;