published fresh until

React Native: store tokens and API keys securely

Summary Keep provider secrets on your server, persist runtime session credentials with react-native-keychain 10.0.0, and delete the matching service with Keychain.resetGenericPassword

Not for Expo SecureStore/Expo Go, browser React/Next.js storage, Flutter or Capacitor (stack choice: see react-native-expo-flutter-or-capacitor-for-a-react-typescript-team); react-native-keychain 9.x/Conceal migration; Expo login-route guards (see expo-router-login-redirect-protected-routes-stack-protected)

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: run npm ls react-native react-native-keychain --depth=0 and classify the credential as a server-owned secret or a user session value received after sign-in before choosing its storage path.

As of November 2026, this guide targets native-managed React Native 0.88 on iOS/Android and react-native-keychain 10.0.0. Follow the RN security guide, updated 2026-10-27. The 10.0.0 release requires Android API 23 or higher and removes FacebookConceal. Existing Conceal data needs a separate migration plan before adopting v10.

1. The credential grants your app privileged provider access → keep it behind your server

As of November 2026, React Native 0.88: follow Storing Sensitive Info. Move privileged API keys, OAuth client secrets and service-account private keys into the backend that calls the provider. Have the app authenticate to that backend with the user's session. Environment-variable injection, native constants and build-time config do not make a credential secret once it ships to devices. Copying a bundled secret into Keychain on first launch does not fix its exposure.

Check: inspect the actual release bundle/resources and source maps for credential names and known secret material; inspect a request to confirm the mobile app calls your backend without the provider secret. Use disposable credentials for this check.

2. A user session must survive restart → use Keychain/Keystore through the native module

As of November 2026, React Native 0.88 with Keychain 10.0.0: follow the tagged installation README. Add react-native-keychain@10.0.0 with the project's package manager, run pod install in ios/, then rebuild both native targets. A JavaScript reload cannot add a native module.

Follow version-pinned credential API. For a disposable local check:

import * as Keychain from 'react-native-keychain';
const scope = { service: 'app.session' };
const written = await Keychain.setGenericPassword('session', 'x', scope);
if (!written) throw new Error('Session write failed');
const saved = await Keychain.getGenericPassword(scope);
if (!saved || saved.password !== 'x') throw new Error('Session read failed');

In the sign-in flow, store the server-issued refresh credential instead of the dummy. Handle rejected promises and false results without logging credential values. Keep tokens out of AsyncStorage, persisted Redux state, analytics and crash breadcrumbs; use memory for session material that need not persist. RN storage guidance.

Check: save the dummy, kill and reopen the app, read the same service, then repeat with sign-in and a refresh request. Remove the dummy afterwards. Check both device platforms and the release build, not only the JavaScript mock.

3. The policy requires tighter device access → select an explicit platform restriction

As of November 2026, Keychain 10.0.0 on RN 0.88: follow the tagged option types and enums. On iOS, pass accessible: Keychain.ACCESSIBLE.WHEN_UNLOCKED_THIS_DEVICE_ONLY when saving a credential that should be available only while unlocked and should not migrate to another device. This is an iOS option, not an Android lock-state guarantee; background refresh while locked needs a different policy.

On Android, if hardware-backed storage is a product requirement, pass securityLevel: Keychain.SECURITY_LEVEL.SECURE_HARDWARE when saving and handle failure as an unsupported-device/sign-in path rather than silently writing plaintext. The API also exposes Keychain.getSecurityLevel() for inspecting device capability. Hardware support is not universal. Android enforcement.

Check: write a fresh disposable entry under the chosen policy, exercise locked/unlocked access where applicable, and run the Android path on a device without the required capability. Confirm the failure UI preserves sign-in recovery. Do not change an existing credential's policy and assume old entries were rewritten automatically. Keychain/Keystore encryption and a biometric prompt are separate choices; this branch does not configure biometrics.

4. Logout or reinstall brings the old account back → delete the same service explicitly

As of November 2026, Keychain 10.0.0 on RN 0.88: follow the version-pinned credential API. On sign-out, await Keychain.resetGenericPassword({ service: 'app.session' }), check its result, clear in-memory session state, and end the server session through your existing authentication backend. Never interpret a local delete as proof that the server revoked the credential.

Check: sign out, cold-launch, and confirm getGenericPassword returns false for that service and the app requests sign-in. If the backend supports revocation, confirm an old refresh credential is rejected. Repeat for each account/service your app stores. On iOS, Keychain entries can survive uninstall/reinstall; do not use uninstall as logout or let a restored entry bypass your backend's session validation. Persistence behavior.

Evidence and limits

Prajwaltechversant's issue #801, opened 2026-08-13, reports Keychain 10.0.0 throwing when a second React instance creates another Android DataStore for the same file. The report concerns multi-instance native hosts; it does not establish a universal v10 failure or a released fix. If your host creates multiple React instances, reproduce that lifecycle with a disposable entry before adopting this path; a single successful get/set is insufficient.

The official API and release note establish storage calls and requirements, not an end-to-end security audit of an app. A compromised process can still access credentials it is authorized to read. Storage loss or access denial must lead to recoverable sign-in; do not use the device store as the only copy of irreplaceable data. A native host compatibility failure needs a native fix, never a fallback that persists the token in plaintext.

Not for: Expo SecureStore/Expo Go, browser React/Next.js storage, Flutter or Capacitor (stack choice: see react-native-expo-flutter-or-capacitor-for-a-react-typescript-team); react-native-keychain 9.x/Conceal migration; Expo login-route guards (see expo-router-login-redirect-protected-routes-stack-protected); leaked-key incident cleanup (see agent-committed-api-key-block-pushes-and-clean-up); app performance or OTA delivery; non-secret preferences; see react-native-settings-asyncstorage-or-mmkv.

Started from a post by @DorianMazur / react-native-keychain, packaged by the editor. Original post

Subjects

More in security

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# React Native: store tokens and API keys securely
Summary: Keep provider secrets on your server, persist runtime session credentials with react-native-keychain 10.0.0, and delete the matching service with `Keychain.resetGenericPassword`
Copy for agent
get the whatworks thread react-native-store-tokens-api-keys-securely-keychain and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread react-native-store-tokens-api-keys-securely-keychain
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp