useMaybeDoormanUser
This hook lets you access the current user (and signOut function) on screens where the user may or may not be signed in.
1
const [user, signOut] = useMaybeDoormanUser()
Copied!
If you want to access the user on a screen where a user may or may not be signed in, then use useMaybeDoormanUser instead:
1
import React from 'react'
2
import { Text } from 'react-native'
3
import { useMaybeDoormanUser } from 'react-native-doorman'
4
5
const MaybeUserDetails = () => {
6
// 👇 notice that the ARRAY syntax (not {} this time!)
7
const [user, signOut] = useMaybeDoormanUser()
8
9
// check if the user is defined or not first
10
if (!user) {
11
// if it isn't, then no one is signed in yet!
12
return <Text>Not signed in yet!</Text>
13
}
14
15
// Ok, now we now there is a user! 🔥
16
const uid = user.uid
17
const phoneNumber = user.phoneNumber
18
19
return <Text>uid: {uid}, phone: {phoneNumber}</Text>
20
}
21
22
export default MaybeUserDetails
Copied!
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.
Copy link