@@ -129,13 +129,12 @@ export class EncryptionManagerComponent implements OnInit {
129129 . then ( ( content ) => {
130130 let cryptoConfig = JSON . parse ( content ) as PouchdbCryptConfig
131131
132- if ( cryptoConfig . key && cryptoConfig . config ) {
133- return PouchdbCrypto . StoreCryptConfig ( cryptoConfig )
134- } else {
135- //throw an error & notify user
132+ if ( ! cryptoConfig . key || ! cryptoConfig . config ) {
136133 this . importCustomFileError = "Invalid crypto configuration file"
137134 throw new Error ( this . importCustomFileError )
138135 }
136+
137+ return PouchdbCrypto . StoreCryptConfig ( cryptoConfig )
139138 } )
140139 . then ( ( ) => {
141140 //go to step 2
@@ -156,13 +155,17 @@ export class EncryptionManagerComponent implements OnInit {
156155 } )
157156 . catch ( ( err ) => {
158157 console . error ( err )
159- //an error occurred while importing credential
160- const toastNotification = new ToastNotification ( )
161- toastNotification . type = ToastType . Error
162- toastNotification . message = "Provided encryption key does not match. Please try a different key"
163- toastNotification . autohide = false
164- this . toastService . show ( toastNotification )
158+ // delete invalid encryption key
165159 this . currentStep = 1
160+ return PouchdbCrypto . DeleteCryptConfig ( this . fastenDbService . current_user )
161+ . then ( ( ) => {
162+ //an error occurred while importing credential
163+ const toastNotification = new ToastNotification ( )
164+ toastNotification . type = ToastType . Error
165+ toastNotification . message = "Provided encryption key does not match. Please try a different key"
166+ toastNotification . autohide = false
167+ this . toastService . show ( toastNotification )
168+ } )
166169 } )
167170 }
168171
0 commit comments