Alternative to the Ionic Secure Storage plugin¶
Looking for a secure storage solution for your Capacitor app? With Ionic discontinuing their commercial Secure Storage plugin, developers need reliable alternatives for encrypted data storage. The Capawesome SQLite plugin and Capawesome Secure Preferences plugin provide modern, secure solutions that address the functionality gap left by Ionic Secure Storage.
Introduction¶
Ionic Secure Storage has been a go-to solution for developers requiring encrypted local storage in their Capacitor applications. However, following Ionic's acquisition by OutSystems and their announcement to phase out commercial products, developers must find alternative solutions for secure data storage. The plugin offered both key-value storage and SQLite database functionality with 256-bit AES encryption, making it essential for applications handling sensitive data.
The Capawesome SQLite plugin and Capawesome Secure Preferences plugin emerge as comprehensive alternatives, providing enterprise-grade security features while maintaining the functionality developers relied on with Ionic Secure Storage.
Migration from Ionic Secure Storage¶
Migrating from Ionic Secure Storage requires choosing the appropriate replacement based on your storage needs: key-value storage or SQLite database functionality.
Key-Value-Store¶
For applications using Ionic Secure Storage's key-value functionality, migrate to the Capawesome Secure Preferences plugin.
Installation¶
Begin by removing the existing Ionic Secure Storage dependency and installing the Capawesome alternative, if you haven't already. To install the Capawesome Secure Preferences plugin, please refer to the Installation section in the plugin documentation.
Create a store¶
Unlike Ionic Secure Storage, the Capawesome Secure Preferences plugin doesn't require explicit store creation. The secure storage is automatically available after installation and the encryption key is managed by the plugin itself, ensuring a seamless experience.
Ionic Secure Storage:
import { KeyValueStorage } from '@ionic-enterprise/secure-storage';
const createStore = async () => {
await KeyValueStorage.create('my-secret-key');
};
Capawesome Secure Preferences:
import { SecurePreferences } from '@capawesome-team/capacitor-secure-preferences';
// No store creation needed - ready to use immediately
Set a value¶
Ionic Secure Storage:
import { KeyValueStorage } from '@ionic-enterprise/secure-storage';
const setValue = async () => {
await KeyValueStorage.set('username', 'john_doe');
};
Capawesome Secure Preferences:
import { SecurePreferences } from '@capawesome-team/capacitor-secure-preferences';
const setValue = async () => {
await SecurePreferences.set({
key: 'username',
value: 'john_doe'
});
};
Get a value¶
Ionic Secure Storage:
import { KeyValueStorage } from '@ionic-enterprise/secure-storage';
const getValue = async () => {
const value = await KeyValueStorage.get('username');
return value;
};
Capawesome Secure Preferences:
import { SecurePreferences } from '@capawesome-team/capacitor-secure-preferences';
const getValue = async () => {
const { value } = await SecurePreferences.get({ key: 'username' });
return value;
};
Remove a value¶
Ionic Secure Storage:
import { KeyValueStorage } from '@ionic-enterprise/secure-storage';
const removeValue = async () => {
await KeyValueStorage.remove('username');
};
Capawesome Secure Preferences:
import { SecurePreferences } from '@capawesome-team/capacitor-secure-preferences';
const removeValue = async () => {
await SecurePreferences.remove({ key: 'username' });
};
Clear the store¶
Ionic Secure Storage:
import { KeyValueStorage } from '@ionic-enterprise/secure-storage';
const clearStore = async () => {
await KeyValueStorage.clear();
};
Capawesome Secure Preferences:
import { SecurePreferences } from '@capawesome-team/capacitor-secure-preferences';
const clearStore = async () => {
await SecurePreferences.clear();
};
SQLite¶
For applications using Ionic Secure Storage's SQLite functionality, migrate to the Capawesome SQLite plugin.
Installation¶
Begin by removing the existing Ionic Secure Storage dependency and installing the Capawesome alternative, if you haven't already. To install the Capawesome SQLite plugin, please refer to the Installation section in the plugin documentation.
Opening a database¶
Database initialization differs between the two solutions. Here's how to adapt your database setup:
Ionic Secure Storage:
import { SQLite } from '@ionic-enterprise/secure-storage';
const openDatabase = async () => {
const db = await SQLite.create({
name: 'database.db',
location: 'default',
});
await db.executeSql('CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT, email TEXT)', []);
return db;
};
Capawesome SQLite:
import { Sqlite } from '@capawesome-team/capacitor-sqlite';
const openDatabase = async () => {
const { databaseId } = await Sqlite.open({
path: 'database.db',
upgradeStatements: [
{
version: 1,
statements: [
'CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT, email TEXT)'
]
}
]
});
return databaseId;
};
Executing SQL statements¶
SQL execution patterns are streamlined in the Capawesome SQLite plugin:
Ionic Secure Storage:
import { SQLiteObject } from '@ionic-enterprise/secure-storage';
const insertUser = async (db: SQLiteObject, name: string, email: string) => {
await db.executeSql(
'INSERT INTO users (name, email) VALUES (?, ?)',
[name, email]
);
};
Capawesome SQLite:
import { Sqlite } from '@capawesome-team/capacitor-sqlite';
const insertUser = async (databaseId: string, name: string, email: string) => {
await Sqlite.execute({
databaseId,
statement: 'INSERT INTO users (name, email) VALUES (?, ?)',
values: [name, email]
});
};
Querying data¶
Data retrieval follows similar simplification patterns:
Ionic Secure Storage:
import { SQLiteObject } from '@ionic-enterprise/secure-storage';
const getUsers = async (db: SQLiteObject) => {
return new Promise((resolve) => {
db.transaction(tx => {
tx.executeSql('SELECT * FROM users WHERE name LIKE ?', ['%John%'], (tx, result) => {
resolve(result.rows);
});
});
});
};
Capawesome SQLite:
import { Sqlite } from '@capawesome-team/capacitor-sqlite';
const getUsers = async (databaseId: string) => {
const result = await Sqlite.query({
databaseId,
statement: 'SELECT * FROM users WHERE name LIKE ?',
values: ['%John%']
});
return result.values;
};
Conclusion¶
The discontinuation of Ionic Secure Storage doesn't have to disrupt your development workflow. The Capawesome SQLite plugin and Capawesome Secure Preferences plugin provide comprehensive alternatives that not only replace the functionality of Ionic Secure Storage but enhance it with modern architecture, better performance, and professional support.
By migrating to these Capawesome plugins, you gain access to actively maintained solutions that stay current with the latest Capacitor versions and platform updates, ensuring your applications remain secure and performant.
To stay updated with the latest updates, features, and news about Capawesome, Capacitor, and Ionic ecosystem, subscribe to the Capawesome newsletter and follow us on X (formerly Twitter).
If you need assistance with migrating from Ionic Secure Storage or implementing the Capawesome SQLite or Capawesome Secure Preferences plugins, the Capawesome team is available to help you transition smoothly to this reliable alternative. Just contact us to get started.