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

# Auth UI

> AuthUI and UserData for login screens.

**Folder:** `Assets/_MolcaSDK/Code/Scripts/Auth/`\
**Namespace:** `MolcaSDK.Auth`

| Type                           | Role                                                                                                                                                                                                         |
| ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **AuthUI**                     | Flat / guest login UI wired to **`AuthManager`** ([RuntimeManager](/core/runtime-manager) subsystem) — not the VR [**ScenarioSessionManager**](/vr/session-authentication) flow unless you bridge separately |
| **UserData** / **SDKUserData** | Guest display name payloads (`GuestLogin`)                                                                                                                                                                   |

## Code

**Inspector-driven:** **`AuthUI`** assigns **`TMP_InputField`**, error texts, **`SharedString nextSceneName`**, and guest panel buttons. On start it **`await RuntimeManager.WaitForInitialization()`**, registers **`AuthEvents.LoggedIn`**, and loads **`nextSceneName.value`** after a successful login.

**Programmatic login** (same as **`OnLoginClicked`**):

```csharp theme={null}
using Molca;
using Molca.Networking.Auth;
using UnityEngine;

public class CustomLogin : MonoBehaviour
{
    public async void Login(string user, string pass)
    {
        await RuntimeManager.WaitForInitialization();
        var auth = RuntimeManager.GetSubsystem<AuthManager>();
        if (auth == null) return;

        bool ok = await auth.LoginAsync(user, pass);
        Debug.Log(ok ? "OK" : "Failed");
    }
}
```

**Guest path** (matches **`OnGuestClicked`** — confirmation modal then **`GuestLogin`**):

```csharp theme={null}
using Molca;
using Molca.Networking.Auth;
using Molca.Modals;

public static void GuestAs(string displayName)
{
    RuntimeManager.GetSubsystem<AuthManager>()
        .GuestLogin(new SDKUserData("Guest", displayName));
}
```

VR OTP / member flows stay on **ScenarioSessionManager** — see [Session authentication](/vr/session-authentication).

## Troubleshooting

* **Scene does not load after login** — **`AuthEvents.LoggedIn`** must fire; **`SharedString`** **`nextSceneName`** must match a registered scene. Check **`SceneLoadManager`** / build settings.
* **Login always fails** — Verify **AuthManager** subsystem, backend URL/auth config in your project, and that **`LoginAsync`** errors surface (UI sets a generic invalid-credentials message on **`usernameErrorText`** only for the main path).
* **Guest panel stuck** — **`guestPanel`** Show/Hide is manual from buttons; ensure **`guestLoginCancelButton`** clears the panel.
* **Start race** — **`AuthUI`** awaits **`WaitForInitialization`**; do not call **`LoginAsync`** from **`Awake`** on the same object before that completes.

## Related

* [RuntimeManager](/core/runtime-manager)
* [Session authentication](/vr/session-authentication) — VR session / OTP
* [Modal manager](/core/modal-manager) — guest confirmation
* [GameManager](/shared/game-manager) — global HTTP UX (orthogonal to login)

## Unity Editor

<Frame caption="AuthUI Inspector">
  <img src="https://mintcdn.com/ptmolcateknologinusantara/qXrgFMk4QevJTANv/images/features/shared/auth-ui-inspector.png?fit=max&auto=format&n=qXrgFMk4QevJTANv&q=85&s=54e4fbcbc3b25164dcf0f4e8dd8b5c89" alt="Auth Ui Inspector" width="928" height="620" data-path="images/features/shared/auth-ui-inspector.png" />
</Frame>
