Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

238
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda