I’m trying to initialize the secure storage plugin. When this fails it means the user does not have a secure lockscreen set. Using the github page i’m trying to recreate the sample provided:
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();
This is my attempt:
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 problem i’m having is that when the secureStorageApi.create call fails, secureStorage will be undefined so I can’t use it to call call secureDevice().
I’m probaly wrong, but this feels like it is impossible to archieve this?
Any help or direction to look would be much appreciated.