Skip to content
Advertisement

How do I update my NavBar once a user is logged-in (from ‘log in’ to ‘profile’) using React & Firebase?

I’m new to Reactjs & Firebase, but I’ve managed to set up a signup/login system- now once the user logs in, I have them redirected back to the home page, but I want the nav bar to display ‘profile’ instead of the original ‘log in’. I know this is something to do with Conditional Rendering but I’m having trouble implementing it with Firebase.


NavBar.js

JavaScript

LogIn.js

JavaScript

AuthContext.js

JavaScript

Advertisement

Answer

I think you should be able to do this:

JavaScript

So the line with useAuth().currentUser will get the user from the context / provider.

And the line with { user && <xxx /> } will be rendered when there is a user.

And the line with { !user && <xxx /> } will be rendered when there is no user.

Advertisement