Skip to content

Guest Mode

Methods

SignUpGuest

Create a guest account without requiring email or password authentication.

Method Signature:
public async UniTask<AuthResponse> SignUpGuest()
Parameters:
  • None
Returns:
  • UniTask<AuthResponse> - Authentication response with guest user info and tokens
AuthResponse Structure:
public class AuthResponse
{
    public AuthPlayerResponse Player { get; set; }
    public string Token { get; set; }
    public string RefreshToken { get; set; }
}

LinkEmailPassword

Upgrade a guest account to a permanent account with email and password.

Method Signature:
public async UniTask<AuthPlayerResponse> LinkEmailPassword(LinkEmailPasswordRequest request)
Parameters:
  • LinkEmailPasswordRequest request - Email and password linking request
Returns:
  • UniTask<AuthPlayerResponse> - Updated user information
LinkEmailPasswordRequest Structure:
public class LinkEmailPasswordRequest
{
    public string Email { get; set; }
    public string Password { get; set; }
}

Examples

Create Guest Account:
using System;
using UnityEngine;
using Cysharp.Threading.Tasks;
using Openfort.OpenfortSDK;
using Openfort.OpenfortSDK.Model;
 
public class GuestAuthManager : MonoBehaviour
{
    private OpenfortSDK openfort;
    
    private async void Start()
    {
        try
        {
            openfort = await OpenfortSDK.Init("YOUR_OPENFORT_PUBLISHABLE_KEY");
        }
        catch (Exception e)
        {
            Debug.LogError(quot;Failed to initialize Openfort: {e.Message}");
        }
    }
    
    public async UniTaskVoid SignUpAsGuest()
    {
        try
        {
            var response = await openfort.SignUpGuest();
            Debug.Log(quot;Guest account created: {response.Player.Id}");
            
            // Guest users have no linked accounts initially
            Debug.Log(quot;Linked accounts: {response.Player.LinkedAccounts.Count}");
            
            // Store tokens if needed
            PlayerPrefs.SetString("guest_token", response.Token);
            PlayerPrefs.SetString("guest_refresh_token", response.RefreshToken);
        }
        catch (OpenfortException e)
        {
            Debug.LogError(quot;Guest signup failed: {e.Message}, Type: {e.ErrorType}");
        }
        catch (Exception e)
        {
            Debug.LogError(quot;Unexpected error: {e.Message}");
        }
    }
    
    // Upgrade guest to permanent account with email/password
    public async UniTaskVoid UpgradeGuestAccount(string email, string password)
    {
        try
        {
            var request = new LinkEmailPasswordRequest
            {
                Email = email,
                Password = password
            };
            
            var response = await openfort.LinkEmailPassword(request);
            Debug.Log(quot;Guest upgraded to permanent account: {response.Id}");
            
            // The guest account now has an email linked
            foreach (var account in response.LinkedAccounts)
            {
                Debug.Log(quot;Linked: {account.Provider} - {account.Email}");
            }
        }
        catch (Exception e)
        {
            Debug.LogError(quot;Failed to upgrade guest account: {e.Message}");
        }
    }
}

Upon successful registration, you'll receive a response containing the user information and authentication tokens:

{
  "player": {
    "id": "pla_...",
    "object": "player",
    "createdAt": 1234567890,
    "linkedAccounts": []
  },
  "token": "eyJhbG...",
  "refreshToken": "eyJhbG..."
}

Upgrade a guest user to a logged-in user

Simply call link method to enable the guest user to upgrade their account to a logged-in account using any authentication method of their choice.