Skip to content

Instantly share code, notes, and snippets.

@dpawluk
Created November 4, 2013 17:30
Show Gist options
  • Save dpawluk/7306212 to your computer and use it in GitHub Desktop.
Save dpawluk/7306212 to your computer and use it in GitHub Desktop.
Wrapper to execute code only for logged in users.
onlyLoggedIn = $.get("/api/v2/users/me.json", function(data){
in_or_out = data.user.id; //this variable contains the data for current user's UID
current_path = window.location.pathname;
})
onlyLoggedIn.done(function() {
if(!in_or_out && current_path != 'access/normal'){ //this is what checks to see if UID is null. If it is null, then executes the code below
windlow.location = "https://support.shareholderinsite.com/access/normal";
}
})
onlyLoggedIn.fail(function(){
alert("Error: cannot reach /api/v2/users/me.json") //failure message if endpoint isn't reachable...
window.location = "https://support.shareholderinsite.com/access/normal"
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment