> ## Documentation Index
> Fetch the complete documentation index at: https://docs.playtolia.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Authentication

> Manage player login with PlaytoliaAuth

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

```c# theme={null}
PlaytoliaAuth.PromptLogin();          // dismissable (default)
PlaytoliaAuth.PromptLogin(false);     // non-dismissable — blocks the game scene
```

<Note>Non-dismissable dialogs block all touch input on the game scene behind them.</Note>

### Listening to auth state

```c# theme={null}
void Start()
{
    PlaytoliaAuth.AddListener(OnAuthChanged);
}

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

void OnDestroy() => PlaytoliaAuth.RemoveListener(OnAuthChanged);
```

<Warning>Always remove listeners in `OnDestroy`. Forgetting causes callbacks to fire on destroyed objects.</Warning>

### Checking auth state

```c# theme={null}
bool loggedIn = PlaytoliaAuth.IsLoggedIn();
string token  = PlaytoliaAuth.GetAccessToken();  // empty string if not logged in
AuthState state = PlaytoliaAuth.GetState();       // null if not logged in
```

<Info>Tokens refresh automatically in the background. You don't need to handle expiry manually.</Info>

### Logout

```c# theme={null}
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.

<Card title="Account Management" icon="circle-user" href="/for-unity/account-management">
  Access user profile data after login
</Card>
