Backendless Support
 

User logout API - logouting current user from a Backendless app

The Backendless logout API is a logical counterpart for the User Login API. The logout step is not required for most apps - user session will expire automatically. However, some apps provide the functionality, especially those with a special multiple login policy

The Backendless logout API is very simple - just a single line of code terminates the current session instantly.

Asynchronous API sample (Android and Plain Java):

final AsyncCallback<Void> logoutResponder = new AsyncCallback<Void>()
{
 @Override
 public void handleResponse( Void aVoid )
 {
 boolean isValidLogin = Backendless.UserService.isValidLogin();
 System.out.println( "Is user logged in? - " + isValidLogin );
 }
 @Override
 public void handleFault( BackendlessFault backendlessFault )
 {
 System.out.println( "Server reported an error " + backendlessFault.getMessage() );
 }
};
AsyncCallback<BackendlessUser> loginResponder = new AsyncCallback<BackendlessUser>()
{
 @Override
 public void handleResponse( BackendlessUser backendlessUser )
 {
 boolean isValidLogin = Backendless.UserService.isValidLogin();
 System.out.println( "Is user logged in? - " + isValidLogin );
 System.out.println( "Logging user out" );
 Backendless.UserService.logout( logoutResponder );
 }
 @Override
 public void handleFault( BackendlessFault backendlessFault )
 {
 System.out.println( "Server reported an error " + backendlessFault.getMessage() );
 }
};
System.out.println( "Logging user in" );
Backendless.UserService.login( "spidey@backendless.com", "greeng0blin", loginResponder );
Synchronous API sample (Plain Java only):
System.out.println( "Logging user in" );
BackendlessUser user = Backendless.UserService.login( "spidey@backendless.com", "greeng0blin" );
boolean isValidLogin = Backendless.UserService.isValidLogin();
System.out.println( "Is user logged in? - " + isValidLogin );
System.out.println( "Logging user in" );
Backendless.UserService.logout();
isValidLogin = Backendless.UserService.isValidLogin();
System.out.println( "Is user logged in? - " + isValidLogin );
The code produces the following output:
Logging user in
Is user logged in? - true
Logging user out
Is user logged in? - false

Review related topics:

Is article helpful?