I'm trying to put together a VERY simple login page to test some things out (I'm not a web dev) and I created a script in javascript that sets an authorized variable to TRUE once the user successfully logs in and redirects the user to the index page. Once there, the body onload runs a function that checks to see if the authorized variable is true to allow the user to stay in the index page and than sets it to false.
The thing is that after I refresh the page the variable is now false (which it should be) but the FALSE condition is not running. It keeps running only the true condition.
Any thoughts?
function validate()
{
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
if(username=="" && password=="")
{
alert("Please fill all the fields.")
return true;
}
else if (username=="adm" && password=="test")
{
localStorage.setItem("authorized", true);
window.location.href = "./index.html";
}
else
{
alert("Login failed.")
return true;
}}
function isAutorized(){
localStorage.getItem("authorized")
if (localStorage.getItem("authorized")){
console.log(localStorage.getItem("authorized"))
console.log("variable is TRUE");
localStorage.setItem("authorized", false);
}
else
{
console.log(localStorage.getItem("authorized"))
console.log("variable is FALSE");
window.location.href = "./login.html";
}};