Vai al contenuto

@capgo/capacitor-persistent-account

Manage user accounts with persistent storage, secure session handling, and seamless authentication across app sessions.

Overview

The Capacitor Persistent Account plugin enables secure storage and persistence of user account data between app installations. This plugin ensures that user account information remains available even after app reinstalls, providing seamless user experience and account continuity.

Cross-install persistence

Data survives app uninstall/reinstall cycles πŸ’Ύ

Secure storage

Secure account data storage with system integration πŸ”

Simple API

Clean read/write interface for account management πŸ“Š

Cross-platform

Native iOS and Android implementation πŸ“±

Installation

Terminal window
npm install @capgo/capacitor-persistent-account
npx cap sync

Core API Methods

Data Management

  • saveAccount(options: { data: unknown }) - Securely save account data to persistent storage
  • readAccount() - Retrieve stored account data, returns Promise<{ data: unknown | null }>

Key Features

  • Cross-installation persistence: Account data survives app uninstall and reinstall
  • Secure storage: Uses platform-specific secure storage mechanisms
  • Type flexibility: Store any serializable account data structure
  • Cross-platform support: Native implementation for both iOS and Android

Usage Example

import { PersistentAccount } from '@capgo/capacitor-persistent-account';
// Define your account data structure
interface UserAccount {
userId: string;
username: string;
email: string;
preferences: {
theme: string;
notifications: boolean;
};
}
// Save account data
const accountData: UserAccount = {
userId: '12345',
username: 'john_doe',
email: 'john@example.com',
preferences: {
theme: 'dark',
notifications: true
}
};
await PersistentAccount.saveAccount({ data: accountData });
// Read account data
const result = await PersistentAccount.readAccount();
if (result.data) {
const account = result.data as UserAccount;
console.log('Restored account:', account.username);
} else {
console.log('No account data found');
}

Use Cases

  • User onboarding: Preserve user progress through app reinstalls
  • Account recovery: Restore user sessions after app updates
  • Preferences storage: Maintain user settings and configurations
  • Offline-first apps: Store essential user data locally

Platform Implementation

iOS

  • Utilizes iOS Keychain Services for secure, persistent storage
  • Data survives app deletion and device restores

Android

  • Uses Android Account Manager or shared preferences with backup
  • Maintains data across app reinstalls and device migrations

Security Considerations

  • Account data is stored using platform-specific secure storage
  • Consider data encryption for sensitive information
  • Implement proper data validation when reading stored accounts
  • Follow platform guidelines for user data handling

Documentation

Check the complete documentation for detailed implementation guides and best practices.