title: How to encrypt access tokens in react native using react-native-keychain?
body: <p><a href="https://docs.amplify.aws/lib/auth/manageusers/q/platform/js/#managing-security-tokens" rel="nofollow noreferrer">https://docs.amplify.aws/lib/auth/manageusers/q/platform/js/#managing-security-tokens</a></p>
  <p>So I have tried implementing the encryption for the auth tokens in the react native code that are fetched from the auth package of react-native. And I have written the following code:</p>
  <pre><code>import React, { Component } from 'react';
  import * as Keychain from 'react-native-keychain';
  import AsyncStorage from '@react-native-async-storage/async-storage';
  import { Auth } from 'aws-amplify';
  
  const MYSTORAGE_KEY_PREFIX = '@ACCESSTOKEN:';
  let dataMemory = {};
  
  export default class MyStorage {
    static syncPromise = null;
  
    static setItem(key, value) {
  
      Keychain.setGenericPassword(MYSTORAGE_KEY_PREFIX + key, value);
      dataMemory[key] = value
  
      return dataMemory[key]
    }
  
    static getItem(key) {
  
      return Object.prototype.hasOwnProperty.call(dataMemory, key) ? dataMemory[key] : undefined
    }
  
    static removeItem(key) {
      Keychain.resetGenericPassword()
      return delete dataMemory[key]
    }
  
    static clear() {
      dataMemory = {}
      return dataMemory
    }
    static sync(){
      if (!MyStorage.syncPromise) {
          MyStorage.syncPromise = new Promise((res, rej) =&gt; {
            Auth.currentSession().then(data =&gt; {MyStorage.setItem(data.idToken.jwtToken)})
          });
      }
      return MyStorage.syncPromise;
  }
  
  }
  
  Auth.configure({
    storage: MyStorage
  });
  
  </code></pre>
  <p>Now, Is it the right way to do this? How do I verify if the tokens are encrypted? I'm completely new to this.</p>