Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useAuthUser works only for the first execution in react native #88

Open
fhuel opened this issue Feb 17, 2023 · 2 comments
Open

useAuthUser works only for the first execution in react native #88

fhuel opened this issue Feb 17, 2023 · 2 comments

Comments

@fhuel
Copy link

fhuel commented Feb 17, 2023

I'm working on a react native project with
react: 18.1.0 ,
react-native: 0.70.5,
react-query: 3.39.3,
and @react-query-firebase/auth: 1.0.0-dev.2.

When I try to use useAuthUser as specified in the docs :
const user = useAuthUser(['user'], auth); to get the user object, everything seems to work fine the first time around, but when I try to use the same code to have the user object in a different component, the query remains in loading state indefinitely.

@fassone
Copy link

fassone commented Apr 2, 2023

i have similar issues with react in production. To get the user, i stick to reactQuery

import { useQuery } from "react-query";
const authUser = useQuery(["authUser"], () => auth)

@shaunsaker
Copy link

Also seemed to have issues with useAuthUser in production. I'm currently using a simple hook with unsubscribe functionality. Seems to be working nicely 🙂

import { User } from 'firebase/auth'
import { useEffect, useState } from 'react'

import { auth } from '../services/firebase'

export const useAuthUser = () => {
  const [authUser, setAuthUser] = useState<User | null>(null)

  useEffect(() => {
    const unsubscribe = auth.onAuthStateChanged(authUser => {
      setAuthUser(authUser)
    })

    return () => {
      unsubscribe()
    }
  }, [])

  return authUser
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants