Skip to content

Repository files navigation

react-native-token

Library for managing tokens structured with keychain storage

Feature

  • Simple and easy to use(hook style)
  • Topic-Token Top-down structure
  • Token stored in Keychain storage
  • MIT License

Install

npm i react-native-token || yarn add react-native-token

Setup

This library needs react-native-keychain. Please follow the installation instructions here

Usage

//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}

Methods

  • useTopic
  • setToken
  • getToken
  • deleteToken
  • getAllToken
  • getAllTokenTitle
  • deleteTopic
  • validateToken
  • clear

API

functions

useTopic(topicTitle(String, required)) => RNToken objcet

  • 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
usage
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
usage
import{useTopic}from"react-native-token"constexample=async()=>{lettopic=awaituseTopic("rsa")awaittopic.setToken("test","testValue",testFunction)}

RNToken.getToken(tokenTitle(String, required))

  • Get token
usage
import{useTopic}from"react-native-token"constexample=async()=>{lettopic=awaituseTopic("rsa")awaittopic.getToken("test")}

RNToken.deleteToken(tokenTitle(String, required))

  • Delete token
usage
import{useTopic}from"react-native-token"constexample=async()=>{lettopic=awaituseTopic("rsa")awaittopic.deleteToken("test")}

RNToken.getAllToken()

  • Get all token in topic
usage
import{useTopic}from"react-native-token"constexample=async()=>{lettopic=awaituseTopic("rsa")awaittopic.getAllToken()}

RNToken.getAllTokenTitle()

  • Get all tokenTitle in topic
usage
import{useTopic}from"react-native-token"constexample=async()=>{lettopic=awaituseTopic("rsa")awaittopic.getAllTokenTitle()}

RNToken.clear()

  • Clear Topic
usage
import{useTopic}from"react-native-token"constexample=async()=>{lettopic=awaituseTopic("rsa")awaittopic.clear()}

RNToken.deleteTopic()

  • Delete this topic
usage
import{useTopic}from"react-native-token"constexample=async()=>{lettopic=awaituseTopic("rsa")awaittopic.deleteTopic()}

RNToken.validateToken(tokenTitle(String, required))

  • Run validate function and return result
usage
import{useTopic}from"react-native-token"constexample=async()=>{lettopic=awaituseTopic("rsa")awaittopic.validateToken("test")}

About

Library for managing tokens structured with keychain storage

Resources

Stars

15 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages