DEV Community

Discussion on: Firebase Google Sign in with React

Collapse
 
gathoni profile image
Mary Gathoni

You're welcome 😊

Collapse
 
imabigfan profile image
imabigfan

Hi Mary,
I am trying to use your code for a few days. Keep getting the following message:
Unhandled Rejection (TypeError): Cannot destructure property 'displayName' of 'user' as it is null.
Getting pretty frustrated trying to solve it.

Can you please... help me?

Thread Thread
 
gavranha profile image
Jocimar Lopes

You can use a condition to check IF user is there. Something like this:

useEffect(() => {
    auth.onAuthStateChanged(async (user) => {
        if(user){
            const { displayName, email } = user;
            setUser({
                displayName,
                email,
            });
        }
    });
}, []);
Enter fullscreen mode Exit fullscreen mode