User profile information getting reset after refreshing each page (using Hello.js)

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.js Functions
    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.

+4
3

-. , , , () .

+2

, , , cookie / . , (, ). , localStorage, , . WWW. ? , Cookies, Json Web Tokens, Session State .. , ID, , Cookie, Query Param, localStorage .. , , OAuth . hello.js, . , , , hello.js , - .

+2

:

Adin DanArl, - , - , cookie .

, jshint:

10  Use '!==' to compare with 'null'.
31  Missing semicolon.
34  Missing semicolon.
Three undefined variables
1   angular
4   hello
13  hello
14  hello
23  hello
15  getUserFromMyOwnAPI

"", "" "userService". (: https://docs.angularjs.org/guide/di, AngularJS)

:

, - - :

GET graph.facebook.com/debug_token?
     input_token={token-to-inspect}
     &access_token={app-token-or-admin-token}

Source: https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow/v2.1#checktoken

Then you may have a chance to pass this information to helljs (I'm used to this library)

0
source

All Articles