SecureStore - is empty after app restarts in expo (via watchdog e.g.)

#1

… is that a normal behavior?

Regards & thanks

#2

hi! this is not normal behavior. what is watchdog?

also, please provide a mcve (https://stackoverflow.com/help/mcve) so we can repro ourselves and help debug

#3

Hi notbrent,
watchdog observes changes in the sourcecode and restarts the app after changes automatically.
I store user informations in the SecureStore API part of Expo.

setCredits(c){
       this.credits = c;
       try{
           Expo.SecureStore.setItemAsync(CREDITS_STORAGE_ID,this.credits);
       }catch(e){
           console.log("Expo.Secure issue:",this.credits);
           console.log("Expo.Secure issue:",CREDITS_STORAGE_ID);
           console.log("Expo.Secure issue:",e);
       }
   }

Later, when I try to read from the SecureStorage in the next session(after restart the app), I get a “null” value.

Expo.SecureStore.getItemAsync(CREDITS_STORAGE_ID).then((data)=>{
            console.log("Storage content:",data);
        });

The code lines are part of an es6 class and running in same scope.

#4

why would you use watchdog and not the built-in livereload?

#5

I thought watchdog is built-in.

#6

it seems expo tries to youse watchdog, if exists. sometimes I get an error, that watchdog isn’t running.

#7

but I think, thats not the topic.

#8

right, so the code you provided is far from a mcve (https://stackoverflow.com/help/mcve) - i tried it and substituted the variables that weren’t defined with random values and it worked as expected. please read and follow the mcve link that i sent.

here’s the code that i ran:

import React from 'react';
import { Button, View, Text } from 'react-native';
import { SecureStore } from 'expo';

export default class Example extends React.Component {
  state = { thing: '' }

  render() {
    return (
      <View style={{flex: 1, alignItems: 'center', justifyContent: 'center'}}>
        <Text>{this.state.thing ? this.state.thing : ''}</Text>
        <Button title="Save the thing" onPress={this._save} />
        <Button title="Get the thing" onPress={this._get} />
      </View>
    );
  }

  _save = async () => {
    await SecureStore.setItemAsync('lol', 'example');
    alert('saved!')
  };

  _get = async () => {
    let result = await SecureStore.getItemAsync('lol');
    this.setState({ thing: result })
  };
}
1 Like
closed #9

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.