Created
September 1, 2018 01:43
-
-
Save jason-dark/6a1d934e609061b19325c7c80e4ada46 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- auth state function --> | |
<script> | |
var privatePages = [ | |
'/private' | |
]; | |
var publicPages = [ | |
'/sign-up', | |
'/log-in' | |
]; | |
firebase.auth().onAuthStateChanged(function (user) { | |
var currentPath = window.location.pathname; | |
if (user) { | |
// User is signed in. | |
if (publicPages.includes(currentPath)) { | |
window.location.replace('/'); | |
} else { | |
console.log('User is logged in!'); | |
console.log('Email: ' + user.email); | |
console.log('UID: ' + user.uid); | |
signupLink.style.display = 'none'; | |
loginLink.style.display = 'none'; | |
loadingScreen.style.display = 'none'; | |
} | |
} else { | |
// User is signed out. | |
if (privatePages.includes(currentPath)) { | |
window.location.replace('/'); | |
} else { | |
console.log('No user is logged in'); | |
privateLink.style.display = 'none'; | |
logoutLink.style.display = 'none'; | |
loadingScreen.style.display = 'none'; | |
} | |
} | |
}); | |
</script> | |
<!-- loading screen css --> | |
<style> | |
.loading-screen { | |
display: flex; | |
} | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment