Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

138
Visualizações
Async storage cannot retrieve data from react native

I am using AsyncStorage to keep user data to phone. After registering the user, i am trying to retrieve the user if exist one and automate redirect to profile page. but I have problems with async storage because it returns only the word 'user' in the console...

in the login component -> import AsyncStorage from '@react-native-async-storage/async-storage';

const loggedUser = async () => {
    try {
        const u = await AsyncStorage.getItem('user');
        console.log(u);
    } catch (error) {
        console.log(error);
    }
};
/**
 * 
 * This function retrieve the data from the server and store it to the local database..
 * 
 */

const executeLogin = async (email, password) => {
    try 
        {
            // Get data and store in async storage
            const response = await data.post('/api/login', {email, password});    
            storeData('user', response.data); -> //Check the code bellow for the source
        } 
        // Catch all errors bellow
        catch (error) 
        {
            if (error.response.status === 404 && error.response.data === 'Wrong credentials') {
                Alert.alert('Whoops!', 'You entered the wrong credentials. Please try again.');
            }
            else {
                Alert.alert('Whoops!', 'Something went wrong. This is an unexpecred error. We will try to fix it as soon as possible');
            }
        }
};

export default executeLogin;

The code block above calls the axios and supose to store the data to async storage. But I have no ideea also if it worked because it gave me no error...

import AsyncStorage from '@react-native-async-storage/async-storage';

/**
 * 
 * This function must only accept serialised object with JSON.stringfy() method
 * 
 */
const storeData = async object => {
    try 
    {
        await AsyncStorage.setItem('user', object);
    } 
    
    catch (error) 
    {
        console.log(error);
    }
} 

export default storeData;

This is the store function

Cannot understand what I am doing wrong.... Thanks, Daniel

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda