Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

use of Cordova's secure storage plugin produces "Unknown provider" error, why?

I'm trying to user Secure storage (https://ionicframework.com/docs/v2/native/secure-storage/) on Ionic application.

In my controller:

    .controller('ExampleCtrl', function ($scope, SecureStorage) {
        var ss = new SecureStorage(
                function () {
                    console.log('Success')
                },
                function (error) {
                    console.log('Error ' + error);
                },
                'my_app');
                var key = 'aaa';

ERROR:

ionic.bundle.js:26799 Error: [$injector:unpr] Unknown provider: SecureStorageProvider <- SecureStorage <- ExampleCtrl

But it don't know the SecureStorage provider.

Do you know what i'm doing wrong?

like image 558
anubis Avatar asked Nov 08 '22 04:11

anubis


1 Answers

Please try this:

.controller('ExampleCtrl', function ($scope) {
    var ss = new cordova.plugins.SecureStorage(
            function () {
                console.log('Success');
            },
            function (error) {
                console.log('Error ' + error);
            },
            'my_app');
});

So, remove SecureStorage from the controller arguments and add cordova.plugins. on the second line.

And don't forget to install the plugin (of course):

ionic plugin add cordova-plugin-secure-storage --save

Now you can use the functions on ss, but don't use the documentation in the link you provided, since this is Ionic 2 documentation. Use the plugin documentation in stead: https://github.com/Crypho/cordova-plugin-secure-storage

like image 121
JanP Avatar answered Nov 15 '22 11:11

JanP