Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save davidystephenson/427a39e8ffe8533e8d09bb8469dd37d6 to your computer and use it in GitHub Desktop.

Select an option

Save davidystephenson/427a39e8ffe8533e8d09bb8469dd37d6 to your computer and use it in GitHub Desktop.
// Observer the body tag of all html files. use validateLogIn function to verfy the login activity
function validateLogIn () {
const uName = document.getElementById('uName')
const signOut = document.getElementById('signout')
signOut.addEventListener('click', () => {
sessionStorage.clear('login')
window.location.href = '../sign-in.html'
})
const sessionLogin = sessionStorage.getItem('login')
if (!sessionLogin) {
alert('You must sign in')
window.location.href = '../sign-in.html'
return
}
const localUser = localStorage.getItem('user')
const user = JSON.parse(localUser)
uName.innerHTML = user.username
}
// Add event listener to every sign out button in the header as asked in the problem statement.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment