Skip to main content
The Authentication component handles login dialogs, session state, and token management. All other components depend on a valid auth state.

Login strategies

Authentication Required (default): The login dialog appears automatically when PlaytoliaGameObject initializes. Best for games that require login from the start. Manual: Disable “Authentication Required” in Playtolia Settings and call PromptLogin() yourself — after a tutorial, at a gated feature, etc.

Prompting login

PlaytoliaAuth.PromptLogin();          // dismissable (default)
PlaytoliaAuth.PromptLogin(false);     // non-dismissable — blocks the game scene
Non-dismissable dialogs block all touch input on the game scene behind them.

Listening to auth state

void Start()
{
    PlaytoliaAuth.AddListener(OnAuthChanged);
}

void OnAuthChanged()
{
    bool loggedIn = PlaytoliaAuth.IsLoggedIn();
    loginPanel.SetActive(!loggedIn);
}

void OnDestroy() => PlaytoliaAuth.RemoveListener(OnAuthChanged);
Always remove listeners in OnDestroy. Forgetting causes callbacks to fire on destroyed objects.

Checking auth state

bool loggedIn = PlaytoliaAuth.IsLoggedIn();
string token  = PlaytoliaAuth.GetAccessToken();  // empty string if not logged in
AuthState state = PlaytoliaAuth.GetState();       // null if not logged in
Tokens refresh automatically in the background. You don’t need to handle expiry manually.

Logout

PlaytoliaAuth.Logout();           // logs out, re-prompts login
PlaytoliaAuth.Logout(false);      // logs out silently

Authentication providers

Enable per-provider in Playtolia Settings: Google, Facebook, Apple (required on iOS), Discord, Email/Password, Guest.

Account Management

Access user profile data after login