Reputation: 125
I'm new of Reactjs and I'd like to understand if the only way to get Firebase currentUser
from context is through onAuthStateChanged
.
I try to be more clear: let's say I signed-in by a "SignIn" component by using Firebase context and, after signed-in, I need to get currentUser
in a different component, it seems to me the only way to get it is something like:
const [user, setUser] = useState(null);
...
useEffect(() => {
props.firebase.auth.onAuthStateChanged(authUser => {
if (!!authUser) {
setUser(authUser);
}
});
}, []);
Is it true?
Thanks
Upvotes: 1
Views: 1723
Reputation: 125
Thanks to who reply my question, I found the answer in this detailed article.
Upvotes: 0
Reputation: 22323
You can use this auth function
const user = firebase.auth().currentUser;
You don't have to store it. Unless you want to.
Upvotes: 2