Skip to content

Set Current User Token

Description

This operation allows setting a new user-token for the current user in the application. The authorization token or user-token is used to maintain the user session, and it uniquely identifies both the user and the session on the server and is used to enforce security policy, apply user and roles permissions and track usage analytics. The authorization token is not stored in the Users data table, but is uniquely generated on every successful login.

When the session expires and this operation is used, the Backendless servers send a new token to the client application to maintain the session.

Method

Future<void> Backendless.userService.setUserToken(userToken);

where:

Argument                Description
userToken A string value uniquely identifying guest user's session. String value.

Return value

The newly assigned token.

Example

The example below sets a new user-token "B8D5D11C-6E07-4E0D-A3F9-B8015F9E4391" for the currently logged in user.

await Backendless.userService.setUserToken("B8D5D11C-6E07-4E0D-A3F9-B8015F9E4391");

Codeless Reference

user_service_codeless_set_current_user_token

Returns the newly assigned token.

Consider the following record in the Users data table:
user_service_codeless_example_get_current_user_2

The example below logs in as "alice@wonderland.com" and sets a new user-token "B8D5D11C-6E07-4E0D-A3F9-B8015F9E4391".

user_service_codeless_example_set_current_user_token_2