I work on a personal project and I use Firebase (by Google) for the authentication of the users. The login works, but I want that the users can access some pages only if they'are connected.
I really don't know where to search.
Here's my code :
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
console.log("connecté");
window.alert("Vous êtes bien connecté");
window.location = 'home.html';
} else {
// No user is signed in.
}
});
function login(){
var userEmail = document.getElementById("mail").value;
var userPassword = document.getElementById("password").value;
firebase.auth().signInWithEmailAndPassword(userEmail, userPassword).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
window.alert("Error : " + errorCode + " " + errorMessage)
});
}
function logout(){
firebase.auth().signOut().then(function() {
console.log("Déconnecté !");
window.alert("Vous êtes bien déconnecté");
}).catch(function(error) {
var errorCode = error.code;
var errorMessage = error.message;
window.alert("Error : " + errorCode + " " + errorMessage)
});
}
'''