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:
@@ -8,3 +8,4 @@ export * from "./reports";
|
||||
export * from "./sessions";
|
||||
export * from "./tags";
|
||||
export * from "./users";
|
||||
export * from "./pgp";
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user