LoginWithOneTimeCode
method in Coherence.Cloud.CoherenceCloud
Methods
public static LoginOperation LoginWithOneTimeCode(string code, CancellationToken cancellationToken = default)
Login to coherence Cloud using a one-time code.
Parameters
| Type | Name | Description |
|---|---|---|
| string | code | One-time code acquired using GetOneTimeCode(CancellationToken). |
| CancellationToken | cancellationToken | Used to cancel the operation. |
Returns
| Type | Description |
|---|---|
| LoginOperation | The status of the asynchronous login operation. |
Remarks
There are two use cases for one-time codes:
- transfer progress from one platform to another,
- recover access to a lost account.
One-time codes expire after a certain time and can only be used once.
'One-Time Code Auth Enabled' must be ticked in Project Settings on your Online Dashboard for this authentication method to be usable.
Examples
using System.Threading.Tasks;
using Coherence.Cloud;
using UnityEngine;
class AcquireOneTimeCode : MonoBehaviour
{
async void Start()
{
PlayerAccount playerAccount = await CoherenceCloud.LoginAsGuest();
string code = await playerAccount.GetOneTimeCode();
Debug.Log($"Login with this code on your other device: {code}.");
}
}
class LoginWithOneTimeCode : MonoBehaviour
{
public async Task<PlayerAccount> Login(string code)
{
var loginOperation = await CoherenceCloud.LoginWithOneTimeCode(code);
if (loginOperation.HasFailed)
{
Debug.LogWarning($"Logging in failed. The code may have already expired.\n{loginOperation.Error}.");
return null;
}
var playerAccount = loginOperation.Result;
Debug.Log($"Logged in as: {playerAccount}.");
return playerAccount;
}
}