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

236
Views
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
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!