useAuthGate

Hook that sets up a listener for the firebase auth and updates the state whenever the user signs in/out, or the user's token refreshes.

This hook is not recommended to use in your app, but it's exposed in case you're doing something custom.

We recommend using the AuthGate component instead, as seen in the quick example. useAuthGate is the hook that is used by the AuthGate.

You would use this if you were making a custom AuthGate component and didn't want to use AuthGate itself.

Usage

Okay, now that I got those disclaimers out of the way, here's how you use this hook:

import { useAuthGate, AuthFlow } from 'react-native-doorman'

const App = () => 

export default () => {
  const { user, loading } = useAuthGate()
  
  if (loading) return <LoadingScreen />
  if (user) return <AuthenticatedApp />
  
  // if there's no authenticated user yet...
  return <AuthFlow />
}

Arguments

Accepts one optional argument. A dictionary with the following field:

  • onAuthStateChanged: Optional function called whenever the auth state changes. Receives one argument: user, which is either null or a firebase user object.

Returns

A dictionary with the following:

  • user either a firebase.User or null

  • loading a boolean that tells you whether or not the auth listener is loading initially.

Last updated