File tree Expand file tree Collapse file tree 2 files changed +13
-3
lines changed
packages/runtime/src/enhancements/node
tests/integration/tests/enhancements/with-encrypted Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -144,7 +144,11 @@ class EncryptedHandler extends DefaultPrismaProxyHandler {
144144 // Don't decrypt null, undefined or empty string values
145145 if ( ! entityData [ field ] ) continue ;
146146
147- entityData [ field ] = await this . decrypt ( fieldInfo , entityData [ field ] ) ;
147+ try {
148+ entityData [ field ] = await this . decrypt ( fieldInfo , entityData [ field ] ) ;
149+ } catch ( error ) {
150+ console . warn ( 'Decryption failed, keeping original value:' , error ) ;
151+ }
148152 }
149153 }
150154 }
@@ -157,7 +161,11 @@ class EncryptedHandler extends DefaultPrismaProxyHandler {
157161
158162 const encAttr = field . attributes ?. find ( ( attr ) => attr . name === '@encrypted' ) ;
159163 if ( encAttr && field . type === 'String' ) {
160- context . parent [ field . name ] = await this . encrypt ( field , data ) ;
164+ try {
165+ context . parent [ field . name ] = await this . encrypt ( field , data ) ;
166+ } catch ( error ) {
167+ throw new Error ( `Encryption failed for field ${ field . name } : ${ error } ` ) ;
168+ }
161169 }
162170 } ,
163171 } ) ;
Original file line number Diff line number Diff line change @@ -23,9 +23,11 @@ describe('Encrypted test', () => {
2323 }` ) ;
2424
2525 const sudoDb = enhance ( undefined , { kinds : [ ] } ) ;
26+ const encryptionKey = new Uint8Array ( Buffer . from ( 'AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8=' , 'base64' ) ) ;
27+
2628 const db = enhance ( undefined , {
2729 kinds : [ 'encrypted' ] ,
28- encryption : { encryptionKey : 'c558Gq0YQK2QcqtkMF9BGXHCQn4dMF8w' } ,
30+ encryption : { encryptionKey } ,
2931 } ) ;
3032
3133 const create = await db . user . create ( {
You can’t perform that action at this time.
0 commit comments