I need to implement a feature in my Firebase real-time database project using JavaScript where the current session is logged out automatically after closing the tab or browser.
When I log in with my email and password, if I copy the URL and paste it into a new tab, it currently displays the same page instead of redirecting to the login screen. I want it to log out the user's session when they close the tab, close the browser, or try to access the page again in a new tab so that they always see the login screen.
function login() {
var email = document.getElementById("email");
var password = document.getElementById("password");
firebase.auth().signInWithEmailAndPassword(email.value, password.value)
.then((result) => {
alert("Login Successful");
console.log(result);
if (email.value == "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="86e7e4e5b7b4b5c6e1ebe7efeaa8e5e9eb">[email protected]</a>") {
window.location.href = "dpr.html"
} else if (email.value == "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="39585b5a080b0a0d795e54585055175a5654">[email protected]</a>") {
window.location.href = "gpr.html"
} else if (email.value == "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a2c3c0c19390919697e2c5cfc3cbce8cc1cdcf">[email protected]</a>") {
window.location.href = "cargo.html"
} else if (email.value == "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="58393a3b696a6b6c6d6e183f35393134763b3735">[email protected]</a>") {
window.location.href = "admin.html"
}
})
.catch(function (error) {
var errorCode = error.code;
console.log(errorCode);
var errorMessage = error.message;
alert("Please Enter the correct password")
})
}