src/user.js
function() {
        if (AV._config.disableCurrentUser) {
          console.warn(
            'AV.User.currentAsync() was disabled in multi-user environment, access user from request instead https://leancloud.cn/docs/leanengine-node-sdk-upgrade-1.html'
          );
          return Promise.resolve(null);
        }

        if (AV.User._currentUser) {
          return Promise.resolve(AV.User._currentUser);
        }

        if (AV.User._currentUserMatchesDisk) {
          return Promise.resolve(AV.User._currentUser);
        }

        return AV.localStorage
          .getItemAsync(AV._getAVPath(AV.User._CURRENT_USER_KEY))
          .then(function(userData) {
            if (!userData) {
              return null;
            }

            // Load the user from local storage.
            AV.User._currentUserMatchesDisk = true;

            AV.User._currentUser = AV.Object._create('_User');
            AV.User._currentUser._isCurrentUser = true;

            var json = JSON.parse(userData);
            AV.User._currentUser.id = json._id;
            delete json._id;
            AV.User._currentUser._sessionToken = json._sessionToken;
            delete json._sessionToken;
            AV.User._currentUser._finishFetch(json);
            //AV.User._currentUser.set(json);

            AV.User._currentUser._synchronizeAllAuthData();
            AV.User._currentUser._refreshCache();
            AV.User._currentUser._opSetQueue = [{}];
            return AV.User._currentUser;
          });
      }
function() {
        if (AV._config.disableCurrentUser) {
          console.warn(
            'AV.User.currentAsync() was disabled in multi-user environment, access user from request instead https://leancloud.cn/docs/leanengine-node-sdk-upgrade-1.html'
          );
          return Promise.resolve(null);
        }

        if (AV.User._currentUser) {
          return Promise.resolve(AV.User._currentUser);
        }

        if (AV.User._currentUserMatchesDisk) {
          return Promise.resolve(AV.User._currentUser);
        }

        return AV.localStorage
          .getItemAsync(AV._getAVPath(AV.User._CURRENT_USER_KEY))
          .then(function(userData) {
            if (!userData) {
              return null;
            }

            // Load the user from local storage.
            AV.User._currentUserMatchesDisk = true;

            AV.User._currentUser = AV.Object._create('_User');
            AV.User._currentUser._isCurrentUser = true;

            var json = JSON.parse(userData);
            AV.User._currentUser.id = json._id;
            delete json._id;
            AV.User._currentUser._sessionToken = json._sessionToken;
            delete json._sessionToken;
            AV.User._currentUser._finishFetch(json);
            //AV.User._currentUser.set(json);

            AV.User._currentUser._synchronizeAllAuthData();
            AV.User._currentUser._refreshCache();
            AV.User._currentUser._opSetQueue = [{}];
            return AV.User._currentUser;
          });
      }
function ( ) { if ( AV . _config . disableCurrentUser ) { console . warn ( 'AV.User.currentAsync() was disabled in multi-user environment, access user from request instead https://leancloud.cn/docs/leanengine-node-sdk-upgrade-1.html' ) ; return Promise . resolve ( null ) ; } if ( AV . User . _currentUser ) { return Promise . resolve ( AV . User . _currentUser ) ; } if ( AV . User . _currentUserMatchesDisk ) { return Promise . resolve ( AV . User . _currentUser ) ; } return AV . localStorage . getItemAsync ( AV . _getAVPath ( AV . User . _CURRENT_USER_KEY ) ) . then ( function ( userData ) { if ( ! userData ) { return null ; } // Load the user from local storage. AV . User . _currentUserMatchesDisk = true ; AV . User . _currentUser = AV . Object . _create ( '_User' ) ; AV . User . _currentUser . _isCurrentUser = true ; var json = JSON . parse ( userData ) ; AV . User . _currentUser . id = json . _id ; delete json . _id ; AV . User . _currentUser . _sessionToken = json . _sessionToken ; delete json . _sessionToken ; AV . User . _currentUser . _finishFetch ( json ) ; //AV.User._currentUser.set(json); AV . User . _currentUser . _synchronizeAllAuthData ( ) ; AV . User . _currentUser . _refreshCache ( ) ; AV . User . _currentUser . _opSetQueue = [ { } ] ; return AV . User . _currentUser ; } ) ; }
Retrieves the currently logged in AVUser with a valid session,
either from memory or localStorage, if necessary.
@return {Promise.<AV.User>} resolved with the currently logged in AV.User.
Retrieves the currently logged in AVUser with a valid session either from memory or localStorage if necessary .