Skip to content

Set Current User

The user-token is treated as a user property across login methods, including the AppleLogin API Service. This method refreshes the value in the LocalStorage (keys: USER_TOKEN | CURRENT_USER_ID | STAY_LOGGED_IN).

If stayLoggedIn=false, the method simply resets the value in the LocalStorage. Then the setCurrentUser method wraps the hash-map object into a BackendlessUser instance, changes the user status to the currentUser, and refreshes the user-token in RT when approriate.

Methods:

function setCurrentUser<T = Backendless.User>(user?: Object, stayLoggedIn?: boolean): T;

Example

const user = await Backendless.UserService.login('user@email.com', 'password')
Backendless.UserService.setCurrentUser(user, true)

Return value:

The server returns true if a token is valid, false otherwise.