I use Hello.js in my AngularJS application to allow users to authenticate with Facebook. After the user logs in and receives user information from Facebook, I use json and get the user object from my own database and save it in the root area, so that various areas on my site can access the user profile information (for example, in the header, where the displayed username is displayed).
Here is a service that handles authentication material
angular.module('myApp')
.factory('userService', function($rootScope, $location) {
hello.init({
facebook : '1234567891234545'
});
var service = {
isLoggedIn: function() {
return $rootScope.loggedInUser != null;
},
login: function() {
hello('facebook').login( function() {
hello('facebook').api('/me').success(function(json) {
$rootScope.loggedInUser = getUserFromMyOwnAPI(json.id);
$rootScope.$apply(function() {
$location.path('/');
});
});
});
},
logout: function() {
hello('facebook').logout( function() {
$rootScope.loggedInUser = null;
$location.path('/');
});
},
loggedInUser: function(){
return $rootScope.loggedInUser;
}
}
return service;
})
, , , , , . , $rootScope.loggedInUser, ( json, Facebook), reset .
? localStorage rootScope? - ( "facebook" ). Api ('/me') , ?
, hello.js - localStorage:
key: hello
{"facebook":{"state":"","access_token":"blahblahblah","expires_in":6776,"https":"1","client_id":"12345","network":"facebook","display":"none","redirect_uri":"http://adodson.com/hello.js/redirect.html","scope":"basic","expires":1412632794.806}}
, , , localStorage.