Library for managing tokens structured with keychain storage
- Simple and easy to use(hook style)
- Topic-Token Top-down structure
- Token stored in Keychain storage
- MIT License
npm i react-native-token || yarn add react-native-token
This library needs react-native-keychain. Please follow the installation instructions here
//import libraryimport{useTopic}from"react-native-token"// this is not requiredimportAPIfrom"aws-amplify"constexample=async()=>{// Create a topic for storing Keys, Tokens ... etc.lettopic=awaituseTopic("rsa")// Set a valueawaittopic.setToken("publicKey",publicKey,validateSessionToken)// Get all tokens that stored in Topiclettokens=awaittopic.getAllToken()letpublicKey=tokens.publicKey.tokenValueawaittopic.clear()}// IMPORTANT : EXAMPLE FUNCTIONconstvalidateSessionToken=async(token)=>{constresult=awaitAPI.post("rntoken","/tokenValidate",{body: {type: "publicKey",token: token}})returnresult}- useTopic
- setToken
- getToken
- deleteToken
- getAllToken
- getAllTokenTitle
- deleteTopic
- validateToken
- clear
- Create A topic for storing values.
- It only creates a new topic when topic does not exist.
- If already had a topic for 'topicTitle' that you passed, will just return RNToken object
import{useTopic}from"react-native-token"constexample=async()=>{lettopic=awaituseTopic("rsa")}RNToken.setToken(tokenTitle(String, required), tokenValue(String, required), validateFunction(Function, optional))
- Add or Update token in topic
import{useTopic}from"react-native-token"constexample=async()=>{lettopic=awaituseTopic("rsa")awaittopic.setToken("test","testValue",testFunction)}- Get token
import{useTopic}from"react-native-token"constexample=async()=>{lettopic=awaituseTopic("rsa")awaittopic.getToken("test")}- Delete token
import{useTopic}from"react-native-token"constexample=async()=>{lettopic=awaituseTopic("rsa")awaittopic.deleteToken("test")}- Get all token in topic
import{useTopic}from"react-native-token"constexample=async()=>{lettopic=awaituseTopic("rsa")awaittopic.getAllToken()}- Get all tokenTitle in topic
import{useTopic}from"react-native-token"constexample=async()=>{lettopic=awaituseTopic("rsa")awaittopic.getAllTokenTitle()}- Clear Topic
import{useTopic}from"react-native-token"constexample=async()=>{lettopic=awaituseTopic("rsa")awaittopic.clear()}- Delete this topic
import{useTopic}from"react-native-token"constexample=async()=>{lettopic=awaituseTopic("rsa")awaittopic.deleteTopic()}- Run validate function and return result
import{useTopic}from"react-native-token"constexample=async()=>{lettopic=awaituseTopic("rsa")awaittopic.validateToken("test")}