Skip to content

10.X breaks getReactNativePersistence for Expo #8051

@chrysb

Description

@chrysb

Operating System

React Native Expo

Browser Version

50

Firebase SDK Version

^10.8.1

Firebase SDK Product:

Auth

Describe your project's tooling

I'm using Expo Go

Describe the problem

It seems like something in 10X broke react native auth persistence in Expo.

Changing to ^9.19.0 resolves the issue.

Would be nice to fix this in 10.X so that we can benefit from all of the other updates.

Steps and code to reproduce issue

If you implement react native persistence as follows:

import AsyncStorage from '@react-native-async-storage/async-storage'
import { initializeApp, getApps, getApp } from 'firebase/app'
import {
  initializeAuth,
  getReactNativePersistence,
} from 'firebase/auth'

const firebaseAuth = initializeAuth(firebaseApp, {
  persistence: getReactNativePersistence(AsyncStorage),
})

And then in your main app file:

export default function Home() {
  const [loggedIn, setLoggedIn] = useState<boolean | null>(null)

  useEffect(() => {
    const unsubsribe = firebaseAuth.onAuthStateChanged((user) => {
      console.log('Current user, user)
      setLoggedIn(Boolean(user))
    })
    return () => {
      unsubsribe()
    }
  }, [])

  if (loggedIn === false) {
    return <Redirect href='/signin' />
  }

After creating an account, onAuthState is called.

If I kill the app and come back, it is not. The onAuthState never gets called on initial page load.

Also, if you just do getAuth().currentUser it's always null

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions