1. Home
  2. Docs
  3. UniREST Solution 3.5
  4. UniREST Client
  5. Login and Registration
  6. AutoLogin and ReLogin

AutoLogin and ReLogin

When the login successfully occurs, the username and the password are stored into the UniREST Client memory and locally saved in a binary file. The file is stored in your Unity project’s default persistent data location or in the IndexedDB for the WebGL platform.

This operation allows you to perform an immediate login retry (for example, after a temporary internet drop) using the account in memory or perform an automatic login (for example, when your game starts) loading the user credentials from the binary file.

AutoLogin()

The AutoLogin() method performs a login loading the credentials (username and password) from a store location. This method is pretty useful if you want your users to enter the game without re-typing their username and password.

_ = UniRESTClient.Async.AutoLogin(onComplete, autoRegistration);
onCompleteAction<bool>The function to call when the operation is completed.
It must have a boolean parameter. It will be true if everything worked, false otherwise.
autoRegistrationbool
(Optional)
Default: false
If set to true, AutoLogin() creates a new account with random data.
booltrue if everything worked, false otherwise.

Since the AutoLogin() method requires a previously saved account, your user must have logged in successfully first. In a C# Script, the best approach is firstly trying to perform an AutoLogin and then, in case of failure, ask for manual login:

- = UniRESTClient.Async.AutoLogin((bool ok) => 
    {
        if (ok) 
        {
            // User automatically logged in!
        }
        else
        {
            // Here ask for manual login!
            // ...
        }
    });

AutoLogin with automatic registration

If the AutoLogin() method is called with the optional autoRegistration parameter set to true, it performs an automatic account registration generating a random username and password and then performs the login. Basically, the AutoLogin(true) method follows these steps:

  1. checks if a locally saved account exists. If it exists, AutoLogin() just performs the login;
  2. if an account doesn’t exist, AutoLogin() generates a new account with a random username and password, and save it locally;
  3. finally, AutoLogin() performs the login with this auto-generated account.
This method is pretty useful if you don't want to ask the user to type a username and a password. However, take into consideration the possible pros and cons of using this approach.

Relogin()

The Relogin() method makes a login attempt using the last used username and password. This is the fastest method to use if, for example, the login session drops for some reason and you want to immediately re-open the connection.

_ = UniRESTClient.Async.ReLogin(onComplete);
onCompleteAction<bool>The function to call when the operation is completed.
It must have a boolean parameter. It will be true if everything worked, false otherwise.
booltrue if everything worked, false otherwise.
- = UniRESTClient.Async.ReLogin((bool ok) => 
    {
        if (ok) 
        {
            // User automatically re-logged in!
        }
        else
        {
            // Login failed. Do something for managing this issue.
            // ...
        }
    });

For both methods, in case of failure, a special code is released to the UniRESTClient class. See the ''Technical Details'' chapter for more info.

rememberMe

The rememberMe property is set to true by default and asks the UniREST Client to save the user account locally so as to allow the use of the AutoLogin() method.

If for some reason you don’t want the user account to be saved locally and you don’t want to use the AutoLogin() method, you can set the rememberMe property to false.