
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
rn-secure-storage
Advanced tools
Secure Storage for React Native (Android & iOS) - Keychain & Keystore
Secure Storage for React Native (Android & iOS) - Keychain & Keystore
Go to F.A.Q for more information.
With NPM
npm install --save rn-secure-storage
With YARN
yarn add rn-secure-storage
removeAll
added.getAllKeys
added.multiSet
added.multiGet
added.multiRemove
added.getSupportedBiometryType
added.You can still use v2.0.5
// {accessible: ACCESSIBLE.WHEN_UNLOCKED} -> This is only for IOS
import React from "react"
import { Button, SafeAreaView, ScrollView, StatusBar } from "react-native"
import RNSecureStorage, { ACCESSIBLE } from "rn-secure-storage"
const App = () => {
/**
* Set a value from secure storage.
*/
const setItem = () => {
RNSecureStorage.setItem("token", "^W((nXWi~M`$Gtu<s+;$`M1SotPG^~", { accessible: ACCESSIBLE.WHEN_UNLOCKED })
.then(res => {
console.log(res)
})
.catch(err => {
console.log(err)
})
}
/**
* Get a value from secure storage.
*/
const getItem = () => {
RNSecureStorage.getItem("token")
.then(res => {
console.log(res)
})
.catch(err => {
console.log(err)
})
}
/**
* Remove a value from secure storage.
*/
const removeItem = () => {
RNSecureStorage.removeItem("token")
.then(res => {
console.log(res)
})
.catch(err => {
console.log(err)
})
}
/**
* Removes whole RNSecureStorage data (It'll return unremoved keys)
*/
const removeAll = () => {
RNSecureStorage.clear()
.then(res => {
console.log(res)
})
.catch(err => {
console.log(err)
})
}
/**
* Checks if a key has been set it'll return tru/false
*/
const itemExist = () => {
RNSecureStorage.exist("@refreshToken")
.then(res => {
console.log(res)
})
.catch(err => {
console.log(err)
})
}
/**
* Get all setted keys from secure storage.
*/
const getAllKeys = () => {
RNSecureStorage.getAllKeys()
.then(res => {
console.log(res)
})
.catch(err => {
console.log(err)
})
}
/**
* Multiple key pair set for secure storage. Will return unsetted keys.
*/
const multiSet = () => {
const pair_one = ["@idToken", "id_token_value"]
const pair_two = ["@accessToken"]
const pair_three = ["@refreshToken", "refresh_token_value"]
RNSecureStorage.multiSet([pair_one, pair_two, pair_three], { accessible: ACCESSIBLE.WHEN_UNLOCKED })
.then(res => {
console.log(res)
})
.catch(err => {
console.log(err)
})
}
/**
* Get multiple values from secure storage.
*/
const multiGet = () => {
RNSecureStorage.multiGet(["@idToken", "@accessToken", "@refreshToken"])
.then(res => {
console.log(res)
})
.catch(err => {
console.log(err)
})
}
/**
* Remove values from secure storage (On error will return unremoved keys)
*/
const multiRemove = () => {
RNSecureStorage.multiRemove(["@refreshToken", "token"])
.then(res => {
console.log(res)
})
.catch(err => {
console.log(err)
})
}
/**
* Get supported biometry type (Will return FaceID, TouchID or undefined)
*/
const getSupportedBiometryType = () => {
RNSecureStorage.getSupportedBiometryType()
.then(res => {
console.log(res)
})
.catch(err => {
console.log(err)
})
}
return (
<SafeAreaView>
<ScrollView>
<Button title="Store Item" onPress={setItem} />
<Button title="Get Item" onPress={getItem} />
<Button title="Remove Item" onPress={removeItem} />
<Button title="Remove All" onPress={removeAll} />
<Button title="Is Item Exist?" onPress={itemExist} />
<Button title="Get All Keys" onPress={getAllKeys} />
<Button title="Multiple Set" onPress={multiSet} />
<Button title="Multiple Get" onPress={multiGet} />
<Button title="Multiple Remove" onPress={multiRemove} />
<Button title="Get Supported Biometry Type" onPress={getSupportedBiometryType} />
</ScrollView>
</SafeAreaView>
)
}
export default App
Key | Platform | Description | Default |
---|---|---|---|
accessible | iOS only | This indicates when a keychain item is accessible, see possible values in Keychain.ACCESSIBLE . | Keychain.ACCESSIBLE.WHEN_UNLOCKED |
Keychain.ACCESSIBLE
enumKey | Description |
---|---|
WHEN_UNLOCKED | The data in the keychain item can be accessed only while the device is unlocked by the user. |
AFTER_FIRST_UNLOCK | The data in the keychain item cannot be accessed after a restart until the device has been unlocked once by the user. |
ALWAYS | The data in the keychain item can always be accessed regardless of whether the device is locked. |
WHEN_PASSCODE_SET_THIS_DEVICE_ONLY | The data in the keychain can only be accessed when the device is unlocked. Only available if a passcode is set on the device. Items with this attribute never migrate to a new device. |
WHEN_UNLOCKED_THIS_DEVICE_ONLY | The data in the keychain item can be accessed only while the device is unlocked by the user. Items with this attribute do not migrate to a new device. |
AFTER_FIRST_UNLOCK_THIS_DEVICE_ONLY | The data in the keychain item cannot be accessed after a restart until the device has been unlocked once by the user. Items with this attribute never migrate to a new device. |
ALWAYS_THIS_DEVICE_ONLY | The data in the keychain item can always be accessed regardless of whether the device is locked. Items with this attribute never migrate to a new device. |
This project is licensed under the MIT License - see the LICENSE.md file for details
FAQs
Secure Storage for React Native (Android & iOS) - Keychain & Keystore
The npm package rn-secure-storage receives a total of 2,791 weekly downloads. As such, rn-secure-storage popularity was classified as popular.
We found that rn-secure-storage demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.