skip to Main Content

I’ve followed expo documentation to include this library to my expo managed react native application. SecureStore

I am using:

  • expo: 44.0.5
  • react-native: 0.64.3 (SDK 44)
  • expo-secure-store: 11.1.0
  • expo-dev-client: 0.8.6
  • react & react-dom 18.0.0
  • typescript

In my App.tsx:

import 'expo-dev-client'
import { deleteValueFor, getValueFor, save } from './src/core/infrastructure/storage/secureStore'
import { REFRESH_TOKEN } from './src/core/infrastructure/config/constants'
....

export default function App(): JSX.Element | null {
  ....

  useEffect(() => {
    ;(async () => {
     try {
      const refreshToken = await getValueFor(REFRESH_TOKEN)
      ...
      // things I do whit refreshToken
      ...
     } catch (e) {
      console.warn(e)
     }
    })()
   }, [])

   const login = async (authUser: AuthUser) => {
     const { token, refreshToken, user } = authUser

     if (!user) {
      throw 'Error al obtener los datos del usuario desde el context'
     }

     setToken(token)
     save({ key: REFRESH_TOKEN, value: refreshToken }) // <---- The error occurs here
   }
}

In secureStore.ts

import * as SecureStore from 'expo-secure-store'

export async function save({ key, value }: { key: string; value: string }): Promise<void> {
 await SecureStore.setItemAsync(key, value)
}

export async function getValueFor(key: string): Promise<string | null> {
  try {
   return await SecureStore.getItemAsync(key)
  } catch (error) {
   return null
  }
}

export async function deleteValueFor(key: string): Promise<void> {
  await SecureStore.deleteItemAsync(key)
}

export async function checkAvailability(): Promise<boolean> {
  return SecureStore.isAvailableAsync()
}

I execute this command to run the app in simulator:

expo start --dev-client --ios

The application is running fine inside the simulator, no errors with that. And after I fill login credentials and press in login button, this is the error message I’m getting:

[Unhandled promise rejection: Error: The method or property SecureStore.setItemAsync is not available on ios, are you sure you've linked all the native dependencies properly?]
at http://192.168.1.3:8082/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&hot=false&strict=false&minify=false:111339:321 in _createSuperInternal
at node_modules/expo-modules-core/build/errors/CodedError.js:10:8 in constructor
at http://192.168.1.3:8082/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&hot=false&strict=false&minify=false:111384:321 in _createSuperInternal
at node_modules/expo-modules-core/build/errors/UnavailabilityError.js:9:42 in constructor
at node_modules/expo-secure-store/build/SecureStore.js:103:14 in setItemAsync
at node_modules/expo-secure-store/build/SecureStore.js:97:7 in setItemAsync
at src/core/infrastructure/storage/secureStore.ts:4:8 in save
at src/core/infrastructure/storage/secureStore.ts:3:7 in save
at App.tsx:87:4 in login

I don’t know what’s wrong. Please help.

2

Answers


  1. Chosen as BEST ANSWER

    If anybody is working on a similar issue.

    According to this issue https://github.com/expo/expo/issues/16906

    I had to rebuild my application due to expo-dev-client lib I'd being using in order to generate a new artifact. After that I could save my token using the expo-secure-store functions without problem.


  2. I’ve fixed the error with replacing the expo package with:
    https://github.com/react-native-async-storage/async-storage

    The other alternatives are:https://reactnative.directory/?search=storage

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search