feat: add encryptedKey column to Credential table for calendar integrations (#27154)

Adds encrypted credential storage using a new keyring system:
  - New `encryptedKey` column with AES-256-GCM encryption
  - Decryption in getCalendarsEvents with fallback to legacy `key`
  - buildCredentialCreateData service for credential creation
  - Phase 1: Google Calendar only, other integrations follow
This commit is contained in:
Alex van Andel authored and GitHub committed 2026-01-30 09:15:13 -03:00
1 parent 80e4b1af1f
commit fc9c26e8dd
36 files changed
+308 -34

No files matched your search

@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "public"."Credential" ADD COLUMN "encryptedKey" TEXT;
+10 -9
View File
@@ -300,17 +300,18 @@ model EventType {
}
model Credential {
id Int @id @default(autoincrement())
id Int @id @default(autoincrement())
// @@type is deprecated
type String
key Json
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
userId Int?
team Team? @relation(fields: [teamId], references: [id], onDelete: Cascade)
teamId Int?
app App? @relation(fields: [appId], references: [slug], onDelete: Cascade)
type String
key Json
encryptedKey String?
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
userId Int?
team Team? @relation(fields: [teamId], references: [id], onDelete: Cascade)
teamId Int?
app App? @relation(fields: [appId], references: [slug], onDelete: Cascade)
// How to make it a required column?
appId String?
appId String?
// paid apps
subscriptionId String?
+2
View File
@@ -12,6 +12,7 @@ export const credentialForCalendarServiceSelect = {
},
teamId: true,
key: true,
encryptedKey: true,
invalid: true,
delegationCredentialId: true,
} satisfies Prisma.CredentialSelect;
@@ -21,6 +22,7 @@ export const safeCredentialSelect = {
type: true,
/** Omitting to avoid frontend leaks */
// key: true,
// encryptedKey: true,
userId: true,
user: {
select: {