useMaybeDoormanUser

This hook lets you access the current user (and signOut function) on screens where the user may or may not be signed in.

const [user, signOut] = useMaybeDoormanUser()

If you want to access the user on a screen where a user may or may not be signed in, then use useMaybeDoormanUser instead:

import React from 'react'
import { Text } from 'react-native'
import { useMaybeDoormanUser } from 'react-native-doorman'

const MaybeUserDetails = () => {
  // 👇 notice that the ARRAY syntax (not {} this time!)
  const [user, signOut] = useMaybeDoormanUser()
  
  // check if the user is defined or not first
  if (!user) {
    // if it isn't, then no one is signed in yet! 
    return <Text>Not signed in yet!</Text>
  }
  
  // Ok, now we now there is a user! 🔥
  const uid = user.uid
  const phoneNumber = user.phoneNumber
  
  return <Text>uid: {uid}, phone: {phoneNumber}</Text>
}

export default MaybeUserDetails

You'll notice that you do [user, signOut] using an array instead of squiggly braces. This is done on purpose to make sure this hook is not confused with useDoormanUser.

Last updated