# Ionic secure storage - Ask the user to set a lock screen

**URL:** <https://forum.ionicframework.com/t/ionic-secure-storage-ask-the-user-to-set-a-lock-screen/107481>\
**Category:** Ionic Native\
**Created:** [October 3, 2017, 12:29pm UTC](https://forum.ionicframework.com/t/ionic-secure-storage-ask-the-user-to-set-a-lock-screen/107481 "2017-10-03T12:29:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Juxture](https://avatars.discourse-cdn.com/v4/letter/j/ec9cab/32.png) [@Juxture](https://forum.ionicframework.com/u/Juxture)\
**Post date:** [October 3, 2017, 12:29pm UTC](https://forum.ionicframework.com/t/ionic-secure-storage-ask-the-user-to-set-a-lock-screen/107481/1 "2017-10-03T12:29:22Z")

</div>

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:

```auto
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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![Juxture](https://avatars.discourse-cdn.com/v4/letter/j/ec9cab/32.png) [@Juxture](https://forum.ionicframework.com/u/Juxture)\
**Post date:** [October 4, 2017, 6:28am UTC](https://forum.ionicframework.com/t/ionic-secure-storage-ask-the-user-to-set-a-lock-screen/107481/2 "2017-10-04T06:28:09Z")

</div>

No one has a solution for this? 😶

---

<div class="post-metadata">

**Author:** ![Juxture](https://avatars.discourse-cdn.com/v4/letter/j/ec9cab/32.png) [@Juxture](https://forum.ionicframework.com/u/Juxture)\
**Post date:** [October 6, 2017, 6:32am UTC](https://forum.ionicframework.com/t/ionic-secure-storage-ask-the-user-to-set-a-lock-screen/107481/3 "2017-10-06T06:32:06Z")

</div>

I managed to fix this myself by editing the plugin.

> <https://stackoverflow.com/questions/46520464/ionic-secure-storage-ask-the-user-to-set-a-lock-screen/46583135#46583135>
