In my react app I am trying to redirect using props.history.push()
on the click of a button but unfortunately, it isn't redirecting (yes, I checked if the path exists). This is the exact function that is getting triggered when the button is clicked.
If I put props.history.push()
above await firebaseApp.signUp(username, email, password)
then it works, but that doesn't make much sense, as I will be redirected even if I have errors.
const signup = async () => {
try {
await firebaseApp.signUp(username, email, password);
props.history.push("/daily");
} catch (error) {
alert(error.message);
}
};
This is the signUp function defined in firebaseApp class:
async signUp(name, email, password){
await this.auth.createUserWithEmailAndPassword(email, password)
return this.auth.currentUser.updateProfile({
displayName:name
})
What is the solution to this problem?