Skip to main content
Namespace: Molca.Networking.Auth
File: Packages/com.molca.core/Runtime/Networking/Auth/AuthManager.cs
Interface: IAuthManager
Type: RuntimeSubsystem (child of RuntimeManager prefab)

When to use

Use AuthManager when your app needs user authentication with token-based session management. It handles login/logout, cached token validation on startup, and automatic auth header injection on outgoing HTTP requests via AuthTokenInterceptor.

Role

  • LoginLoginAsync(username, password) authenticates via a configured HttpRequestAsset, persists the encrypted user data to SecureStorage.
  • Cached token validationTryValidateCachedToken() loads persisted credentials and validates against the server.
  • Auto-injectionAuthTokenInterceptor automatically adds the auth token header to every outgoing IHttpClient request.
  • Guest loginGuestLogin(data) creates an unauthenticated session for anonymous users.
  • LogoutLogoutAsync() clears local state and notifies the server.

Inspector configuration

API Reference

Code

Events

AuthManager dispatches typed events through EventDispatcher:
  • AuthEvents.LoggedIn — fired after successful login/guest login with AuthLoggedInEventData
  • AuthEvents.LoggedOut — fired after logout/clear with AuthLoggedOutEventData

Troubleshooting

  • TryValidateCachedToken returns false: the cached token has expired or the server endpoint is unreachable. User must log in again.
  • Auth header not sent on requests: ensure authTokenKey matches the header name the server expects. The interceptor fires automatically on requests built through IHttpClient.