Skip to content

feat: Add keychain persistence plugin for React Native#551

Closed
BadLice wants to merge 3 commits intoLegendApp:mainfrom
BadLice:main
Closed

feat: Add keychain persistence plugin for React Native#551
BadLice wants to merge 3 commits intoLegendApp:mainfrom
BadLice:main

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

@jmeistrich
Copy link
Member

Hey, I was just looking at reviewing this but just saw you closed it. I've been distracted with legend list for a while but I'm coming back and looking to merge things 😃

Is this still potentially useful? Or are you preparing a new PR?

@BadLice BadLice reopened this Oct 23, 2025
@BadLice BadLice closed this Oct 23, 2025
@BadLice
Copy link
Author

BadLice commented Oct 23, 2025

Hey, I was just looking at reviewing this but just saw you closed it. I've been distracted with legend list for a while but I'm coming back and looking to merge things 😃

Is this still potentially useful? Or are you preparing a new PR?

i'm sorry, i closed this by mistake. i reopened it here #607

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.

2 participants