Skip to content

Instantly share code, notes, and snippets.

@Satshabad
Created August 23, 2013 08:12
Show Gist options
  • Save Satshabad/6316759 to your computer and use it in GitHub Desktop.
Save Satshabad/6316759 to your computer and use it in GitHub Desktop.
This took me a while
function isLoggedIn() {
var deferred = $q.defer();
Facebook.getLoginStatus().then(function(loginStatus) {
if (!loginStatus.loggedIn) {
resolve(deferred, false);
} else {
user.accessToken = loginStatus.authResponse.accessToken;
user.id = loginStatus.authResponse.userID
var tryToGetMe = Facebook.api('/me'),
tryToGetPic = Facebook.api('/me/picture');
$q.all([tryToGetMe, tryToGetPic]).then(function(results) {
var me = results[0],
pic = results[1];
user.fullName = me.first_name + " " + me.last_name;
user.picture = pic.data.url;
// This is passed to the next "then" function
return {
"accessToken" : user.accessToken,
"fbId" : user.id,
"fullName" : user.fullName,
"imageLink" : user.picture
};
}).then(function(postParams) {
var tryToLogin = $http.post('http://localhost:8000/login', postParams)
tryToLogin.then(function(response) {
resolve(deferred, response.status === 200);
});
})
}
});
return deferred.promise
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment