Skip to content

Logout

Description

The Logout operation terminates user session and disassociates the AuthenticatedUser role from the subsequent requests made by the client application.

Method

- (void)logoutWithResponseHandler:^(void)responseHandler errorHandler:^(Fault * _Nonnull)errorHandler;
func logout(responseHandler: (() -> Void)!, errorHandler: ((Fault) -> Void)!)

where:

Argument                Description
responseHandler Handles successful result of an asynchronous call.
errorHandler Handles fault result of an asynchronous call.

Return Value

None.

Example

The example below terminates the user session.

[Backendless.shared.userService logoutWithResponseHandler:^{
    NSLog(@"User has been logged out");
} errorHandler:^(Fault *fault) {
    NSLog(@"Error: %@", fault.message);
}];
Backendless.shared.userService.logout(responseHandler: {
    print("User has been logged out")
}, errorHandler: { fault in
    print("Error: \(fault.message ?? "")")
})

Errors

The following errors may occur during the Logout API call. See the Error Handling section for details on how to retrieve the error code when the server returns an error.

Error Code
Description
2002
Version is disabled or provided wrong application info (application id or secret key)
3007
Invalid application-id or version.
3023
General error while executing logout. Error details should be available in the message property.

Codeless Reference

user_service_codeless_logout_current_user

This operation does not return a value.

Consider the following record in the Users data table:
user_service_codeless_example_get_user_roles_example_1

The example below logs in as "alice@wonderland.com", retrieves the user token, and terminates the current session by invoking the Logout operation.  The user token is required for successful Logout operation.

user_service_codeless_example_logout_current_user