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

327
Views
Firebase currentUser and onAuthStateChanged

I am developing an app using react native, every time I refresh the app on the emulator in onAuthStateChanged and currentUser from firebase I get null.

I have read about waiting onAuthStateChanged to get a status update but I never do, so I guess I misconfigured something.

I am using expo 44, react 17, firebase 9.6.5 but in compat mode (planning in fully migrate later)

My first attempt of solution was trying to add persistence: firebase.auth().setPersistence(firebase.auth.Auth.Persistence.LOCAL);

import firebase from "firebase/compat/app";
import "firebase/compat/auth";
import "firebase/compat/firestore";
import "firebase/compat/functions";
import "firebase/compat/storage";
import AsyncStorage from "@react-native-async-storage/async-storage";

import { firebaseConfig } from "./firebase/firebaseConfig";

firebase.initializeApp(firebaseConfig);

firebase.firestore();
firebase.functions();
firebase.storage();
firebase.auth();

firebase.auth().setPersistence(firebase.auth.Auth.Persistence.LOCAL);
firebase.auth().onAuthStateChanged(async (user) => {
    console.log("onAuthStateChanged called: ", user);
    if (user) {
        await AsyncStorage.setItem('@isLoggedIn', '1');
    } else {
        await AsyncStorage.setItem('@isLoggedIn', '0');
    }
});

export default firebase;

But I get an error:

undefined is not an object (evaluating 'this.storage.setItem')
at node_modules/@firebase/auth/dist/esm2017/index-cff4f2fd.js:5248:0 in verifyBeforeUpdateEmail
at node_modules/@firebase/auth/dist/esm2017/index-cff4f2fd.js:5420:12 in _fromIdTokenResponse
at http://127.0.0.1:19000/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&hot=false&minify=false:183132:41 in _set
at node_modules/@firebase/auth/dist/esm2017/index-cff4f2fd.js:1414:55 in newData.some$argument_0
at node_modules/@firebase/auth/dist/esm2017/index-cff4f2fd.js:2060:1 in <global>
at node_modules/@firebase/auth/dist/esm2017/index-cff4f2fd.js:2047:30 in _isIOS
at node_modules/@firebase/auth/dist/esm2017/index-cff4f2fd.js:1890:4 in PersistenceUserManager.create
at node_modules/@firebase/auth/dist/esm2017/index-cff4f2fd.js:1890:4 in PersistenceUserManager.create

to Login I use:

userCredential = firebase
          .auth()
          .signInWithEmailAndPassword(data.email, this.state.password);
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I had this exact same issue. I solved it by adding "firebase": "^8.9.1" to package.json, running yarn install and changing the import import firebase from "firebase" (remove all the other imports you have). Apparently selective imports have a bug in v8, but at least it works well :)

over 4 years ago · Santiago Trujillo 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!