Skip to content

feat: Add keychain persistence plugin for React Native #551

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

BadLice
Copy link

@BadLice BadLice commented Jul 10, 2025

This PR introduces a new persistence plugin that enables secure storage of observable state in React Native applications using the device keychain, based on react-native-keychain package

Changes

  • Added react-native-keychain dependency - Required for secure keychain access on iOS and Android
  • Implemented observablePersistKeychain plugin (src/persist-plugins/keychain.ts) - A complete persistence plugin with full CRUD operations for keychain storage
  • Added comprehensive test suite
  • Updated sync types - Added necessary type definitions for the new plugin

Features

  • ✅ Secure storage using device keychain
  • ✅ Graceful error handling with customizable error callbacks
  • ✅ Preloading capabilities

Usage Example

import { observablePersistKeychain } from '@legendapp/state/persist-plugins/keychain';
import { configureSynced } from '@legendapp/state/sync';

const mySynced = configureSynced(synced, {
    persist: {
        plugin: observablePersistKeychain(),
    },
});

const userState = observable({
    token: '',
    preferences: { theme: 'dark' }
});

const state = syncObservable(
    userState,
    mySynced({
        persist: { name: 'secure-user-data' },
    }),
);

This PR addresses issue #548

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant