I'm running into an issue while trying to set up the secure storage plugin. If initialization fails, it typically indicates that the user hasn't configured a secure lock screen. Following guidelines from the project's GitHub page, I am attempting to replicate the provided sample code:
var ss;
var _init = function () {
ss = new cordova.plugins.SecureStorage(
function () {
console.log('OK');
},
function () {
navigator.notification.alert(
'Please enable the screen lock on your device. This app cannot operate securely without it.',
function () {
ss.secureDevice(
function () {
_init();
},
function () {
_init();
}
);
},
'Screen lock is disabled'
);
},
'my_app');
};
_init();
Here is my implementation:
private createSecureStorage() {
this.secureStorageAPI.create(this.storeName).then(
(storage: SecureStorageObject) => {
this.secureStorage = storage;
}).catch(
(error) => {
this.dialogs.alert( 'Please enable the screen lock on your device. This app cannot operate securely without it.').then(
() => {
// Alert Dismissed, should open the secure lockscreen settings here
this.secureStorage.secureDevice().then(
() => {
// Try again
this.createSecureStorage();
}
).catch( () => {
// Try again
this.createSecureStorage();
})
} )
} );
}
The challenge I am facing is that if the secureStorageApi.create call fails, the secureStorage object will be undefined, making it impossible to execute secureDevice().
I would greatly appreciate any assistance with this matter.