Getting started
Keep passwords and tokens in Apple Keychain and Android Keystore, with one API for your React Native app.
react-native-keychain stores a username and a secret together. Use it for a session token, saved sign-in, or credentials tied to a server. You can also require biometrics or a device passcode before access.
Install
npm install react-native-keychainyarn add react-native-keychainpnpm add react-native-keychainInstall the iOS pods and rebuild your app before calling the library. See Installation for requirements, native setup, and Face ID configuration.
Your first credential
Use the same service when saving, reading, and removing a credential. The password field can hold a token as well as a password.
import * as Keychain from 'react-native-keychain';
const options = { service: 'com.example.session' };
// Save after signing in. Replace this sample with your session token.
await Keychain.setGenericPassword('session', 'example-token', options);
// Read when you need the token.
const credentials = await Keychain.getGenericPassword(options);
if (credentials) {
const token = credentials.password;
// Use the token in your authenticated request.
}
// Remove when signing out.
await Keychain.resetGenericPassword(options);A read returns false when no matching credential exists. Authentication and storage failures reject the promise: handle those separately from a missing credential. See Store and retrieve for a complete example with error handling.
Choose a credential API
| You want to store | Use | Identify the entry with |
|---|---|---|
| A token or an app sign-in | setGenericPassword | service |
| Credentials for a server | setInternetCredentials | server |
On iOS, these use different Keychain item classes. On Android, they share a namespace, so use different identifiers for unrelated entries.
Next steps
- Store and retrieve — overwrite entries, store multiple tokens, and work with servers.
- Authentication — require biometrics or a passcode and handle failures.
- Example app — try save, load, and reset on a device.
- API reference — find every function, option, and enum.