Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

255
Views
(SOLVED) React Native - Expo SecureStore API apparently not working

Here's my code (followed this guide: https://docs.expo.dev/versions/latest/sdk/securestore/):

fetch('<APIurl>', {
    method: 'POST',
    body: formBody,
    headers: {
    //Header Definition
    'Content-Type':
    'application/x-www-form-urlencoded;charset=UTF-8',
    },
})
.then((response) => response.json())
.then((responseJson) => {
    console.log(responseJson.id_user);
    // If server response message same as Data Matched
    if (responseJson.status != '0 results') {
    //Alert.alert("Excellent!", "Please go on");
    
    async function save(key, value) {
        await SecureStore.setItemAsync(key, value);
    }
    async function getValueFor(key) {
        let result = await SecureStore.getItemAsync(key);
        if (result) {
        alert("๐Ÿ” Here's your value ๐Ÿ” \n" + result);
        } else {
        alert('No values stored under that key.');
        }
    }

    save(id_user, responseJson.id_user);
    getValueFor(id_user);

    //navigation.navigate('InsertCodeScreen');
    } else {
    console.log('Please check your mobileNumber');
    }
})
.catch((error) => {
    //Hide Loader
    console.error(error);
});

it returns Can't find variable: id_user

Strangely, if I do save(responseJson.id_user, responseJson.id_user); it works perfectly, but if in an another screen I do getValueFor(responseJson.id_user);, the app complains that cannot find responseJson variable.

But by the way, isn't the first argument of save() the name I want to give to the item I want to store?

about 4 years ago ยท Juan Pablo Isaza
1 answers
Answer question

0

Solved: haven't realized before that the "key" for save() must be a string

about 4 years ago ยท Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
ยฉ 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!