Skip to content

Instantly share code, notes, and snippets.

@andreineculau
Last active May 3, 2019 18:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreineculau/76fbd925b7c773ccbea64faf1c74dd56 to your computer and use it in GitHub Desktop.
Save andreineculau/76fbd925b7c773ccbea64faf1c74dd56 to your computer and use it in GitHub Desktop.
if defense of being old and grumpy
function login(user) {
if (!user) {
user = getFromLocalStorage('user');
}
if (user) {
if (user.loggedIn && user.isAdmin) {
navigateTo('dashboard');
}
else {
navigateTo('unauthorized');
}
}
else {
navigateTo('unauthorized');
}
}
function login(user) {
// if the user is null, check local storage to
// see if there is a saved user object there
user = user || getFromLocalStorage("user");
// Make sure the user is not null, and is also
// both logged in and an admin. Otherwise, DENIED. 🌲
user && (user.loggedIn && user.isAdmin)
? navigateTo("dashboard")
: navigateTo("unauthorized");
}
function login(user = getFromLocalStorage('user')) {
if (!user || !user.loggedIn || !user.isAdmin)) {
navigateTo('unauthorized');
return;
}
navigateTo('dashboard');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment