I am building an app that uses react and firebase. I created a login component, where it sets the state "isLoggedIn" to true after they log in and redirects the user to the main page. The problem is that the state is false by default then takes time to set, so when you refresh the main page, you can see the login page briefly. Do I change my router redirect code or set the state differently?
Here is my code:
const [isLoggedIn, setIsLoggedIn] = useState(false)
onAuthStateChanged(auth, (currentUser) => {
setIsLoggedIn(currentUser)
})
return (
<Router>
{isLoggedIn ? <Redirect to="/home" /> : <Redirect to="/login" />}
<Route path="/home" component={SongList} />
<Route path="/login" component={Auth} />
</Router>
)