useDoormanUser

React hook that returns the current firebase Auth user.

For a full walkthrough, see accessing the current user.

import React from 'react'
import { useDoormanUser } from 'react-native-doorman'

export default () => {
  // 🚨 Only use this hook in screens that show up
  // after the user has auth'd
  const { signOut, uid, phoneNumber } = useDoormanUser()

  // ... your render code here
}

This hook should only be used on screens that show up after a user has signed in. If you need to access the user on screens that might show up before someone has signed in, see useMaybeDoormanUser instead.

Higher order component

There is an equivalent HOC, withDoormanUser, that has the exact same API as useDoormanUser. If you wrap your component with it, you can access it through the user prop.

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

function UserDetails(props) {
  // receives a user prop
  const { phoneNumber, uid, signOut } = props.user
  
  return <Text>uid: {uid}, phone: {phoneNumber}</Text>
}

export default withDoormanUser(UserDetails)

Last updated