Last updated
Last updated
So, here you are. You've successfully added phone authentication to your app. You did it.
And now, you're wondering, how do I access the current user inside my authenticated app? 🧐
Before Doorman, this was actually a challenge.
You need access to the current user's details, such as their unique id (uid
) and perhaps their phone number (phoneNumber
). And you also need your components to re-render whenever these change, to make sure there's no stale data.
With Doorman, accessing the current user is easy.
You can either use useDoormanUser
or withDoormanUser
, depending on your preference for React Hooks vs higher order components.
useDoormanUser
and withDoormanUser
should only be used on screens/components that show up after a user has signed in. If you use either of these when a user hasn't authenticated yet, it will throw an error.
If you want to access the user on a screen where a user may or may not be signed in, then use useMaybeDoormanUser
instead:
There is one important caveat for these functions, as mentioned on the useDoormanUser
:
Access the latest user details from any component in your app.