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

237
Visualizações
persist login using expo go and firebase v9

Using the code below from other posts seems to suggest that this works for persisting a user (when the app is closed and launched again) through react native for firebase version 8. However using firebase v9 involves the "firebase/compat" directory which does not contain initializeAuth. Although the code runs for firebase v9 it does not persist the user. Does anyone know a solution for this?

    import { initializeApp } from "firebase/app"
    import { initializeAuth } from "firebase/auth"
    import { getReactNativePersistence } from "firebase/auth/react-native"
    import AsyncStorage from "@react-native-async-storage/async-storage"
    
    const defaultApp = initializeApp(config);
    initializeAuth(defaultApp, {
      persistence: getReactNativePersistence(AsyncStorage)
    });

My sign up flow in auth context:

  try {
    await checkIsValidUsername(userData.username);
    await checkIsValidEmail(userData.email);
    await checkIsValidPassword(password);

    // create in firebase
    const result = await getAuth().createUserWithEmailAndPassword(userData.email, password);

    if (!result || !result.user || !result.user.uid) {
      dispatch({ type: 'error', payload: `Account creation failed for '${userData.email}'` });
      return;
    }

    console.log(`Created account: ${result.user.uid} for ${result.user.email}, ${userData.username}`);

    // save in the account table with the new uid and oddsPreference added in
    await createUser({ ...userData, uid: result.user.uid, oddsPreference });

    // Now try to login with the email and password
    const userCredential = await getAuth().signInWithEmailAndPassword(userData.email, password);
    const user = await getUserByUid(userCredential.user?.uid);

    if (user === null) {
      dispatch({ type: 'error', payload: 'Login failed!' });
    } else {
      // Set the user in context
      dispatch({ type: 'set_user', payload: { ...user, username: user.username, email: user.email,
          oddsPreference: user.oddsPreference } });
    }

    onSuccess();
  } catch (e) {
    dispatch({ type: 'error', payload: e.message });
  } finally {
    dispatch({ type: 'processing', payload: false });
  }
};
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