How can I redirect to a different webpage after the user has signed in?
Currently when a user logs in, data gets retrieved however, it doesn\'t redirect the user to
Get the email and password from user and then pass the values to signInWithEmailAndPassword, if some error occurs it will print the message, if not Firebase will successfully sign the user in.
firebase.auth().signInWithEmailAndPassword(email, password).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
console.log(error.Message);
});
You also need a listener that handles login and logout status. This is where you can redirect users if they have successfully logged in.
To handle login and logout, always use onAuthStateChanged()
//Handle Account Status
firebase.auth().onAuthStateChanged(user => {
if(user) {
window.location = 'home.html'; //After successful login, user will be redirected to home.html
}
});
The moment someone logins, user will be populated with user details and you can use it to redirect to another page.