Skip to content

feat: Add keychain persistence plugin for React Native#607

Open
BadLice wants to merge 2 commits intoLegendApp:mainfrom
BadLice:feature/issue-548
Open

feat: Add keychain persistence plugin for React Native#607
BadLice wants to merge 2 commits intoLegendApp:mainfrom
BadLice:feature/issue-548

Conversation

@BadLice
Copy link

@BadLice BadLice commented Oct 23, 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