@sneko/ionic-appauth
Version:
Intergration for OpenId/AppAuth-JS into Ionic V3/4/5
48 lines (47 loc) • 2.11 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CapacitorSecureStorage = void 0;
var tslib_1 = require("tslib");
require("capacitor-secure-storage-plugin");
var core_1 = require("@capacitor/core");
var SecureStoragePlugin = core_1.Plugins.SecureStoragePlugin;
// REQUIRES CAPACITOR PLUGINS
// capacitor-secure-storage-plugin
var CapacitorSecureStorage = /** @class */ (function () {
function CapacitorSecureStorage() {
}
CapacitorSecureStorage.prototype.getItem = function (name) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var returned;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!SecureStoragePlugin)
throw new Error("Capacitor Secure Storage Is Undefined!");
return [4 /*yield*/, SecureStoragePlugin.get({ key: name })
.catch(function () { return { value: null }; })];
case 1:
returned = _a.sent();
return [2 /*return*/, returned.value];
}
});
});
};
CapacitorSecureStorage.prototype.removeItem = function (name) {
if (!SecureStoragePlugin)
throw new Error("Capacitor Secure Storage Is Undefined!");
return SecureStoragePlugin.remove({ key: name }).then(function () { });
};
CapacitorSecureStorage.prototype.clear = function () {
if (!SecureStoragePlugin)
throw new Error("Capacitor Secure Storage Is Undefined!");
return SecureStoragePlugin.clear().then(function () { });
};
CapacitorSecureStorage.prototype.setItem = function (name, value) {
if (!SecureStoragePlugin)
throw new Error("Capacitor Secure Storage Is Undefined!");
return SecureStoragePlugin.set({ key: name, value: value }).then(function () { });
};
return CapacitorSecureStorage;
}());
exports.CapacitorSecureStorage = CapacitorSecureStorage;