Getting the Current User

When a user logs in, the Kii Cloud SDK gets the user. While the user is logged in, you can get the user with an API.

When a user logs in, the SDK gets the user's access token from Kii Cloud. The SDK then stores the access token along with other user information in its static area for the details on the access token). In another word, the SDK remembers the "current user."

You can get the currently logged-in user by calling the getCurrentUser method.

  • // Get the currently logged-in user.
    var user = KiiUser.getCurrentUser();
    
    // Refresh the user to get the latest user info from Kii Cloud.
    user.refresh().then(
      function(theUser) {
        // Do something.
      }
    ).catch(
      function(error) {
        // Handle the error.
        var theUser = error.target;
        var errorString = error.message;
      }
    );
  • // Get the currently logged-in user.
    var user = KiiUser.getCurrentUser();
    
    // Refresh the user to get the latest user info from Kii Cloud.
    user.refresh({
      success: function(theUser) {
        // Do something.
      },
      failure: function(theUser, errorString) {
        // Handle the error.
      }
    });

Call the refresh method to get the latest user information from Kii Cloud.

If the getCurrentUser method returns null, it means nobody is logged in.

The SDK can only handle one logged-in user at a time. If you want to handle multiple users, you need to login again as a different user. The login state of the previous user is lost by making this user switch.