Automatic login practical guide
To let users who logged in before enter the app directly without going through the login screen when they relaunch the app, you must combine Hive Console settings, Hive Axyl SDK calls, recipe code calls, and app code. With the recipe code, the Hive Axyl SDK calls needed to restore the session come down to a single method.
Implementation scope
The work required to implement automatic login starts with checking the Client ID in the Hive Console and ends with restoring the session with the saved credentials and moving to the app screen when the app is relaunched.
The work in each step falls into the following six categories. A single step can span two categories.
| Category | Owner | Description |
|---|---|---|
| Hive Console | App operator | Settings you configure in the Hive Console. |
| Hive Axyl SDK | App developer | Hive Axyl SDK methods the app calls. |
| Recipe code | App developer | Recipe methods the app calls. |
| App code | App developer | Parts the app implements directly without going through Hive Axyl. |
| Hive Axyl Server API | App server developer | The Hive Axyl Server API that the app server calls. |
| App server | App server developer | Parts the app server handles with its own logic. |
Automatic login has no Add-on calls. An Add-on is a Hive Axyl SDK extension package that displays the authentication screen of an external authentication provider. Automatic login only restores the session with the saved tokens, so it does not need to authenticate the user again. For the meaning of the parameters and the response fields, see the detailed procedure linked in each step.
Recipe
The Hive Axyl SDK provides the session restoration feature as fine-grained methods. The method that logs in with a saved access token, the method that issues new tokens with a refresh token, and the method that activates the session are all separate. To restore the session of a single user, the app must put together the rules that decide which token to use, the call order, and the handling of failures along the way by itself.
A recipe is source code that completes that combination in advance. Instead of installing it as a package, you copy it into your project.
| Category | Location | Characteristics |
|---|---|---|
| Hive Axyl SDK | Unity package com.com2usplatform.hiveaxyl.* | You install and use it. It provides authentication features as fine-grained methods. |
| Recipe | Assets/Recipes/AutoLogin/ | You copy and use it. Plain C# code that groups SDK calls by purpose. |
| Usage example | Assets/RecipeExamples/Authentication/AutoLoginExample.cs | Code you read for reference. Its comments explain the recipe call order and the parts the app must implement for each result. |
Recipes are code you copy and use
Recipes are copied into your app and become your app's code. You can use them as is or modify them to fit your app's policies.
Apps that cannot copy the recipe source into their project implement the same flow by calling the Hive Axyl SDK methods directly. For how to call each step, see Automatic login.
Differences between automatic login and automatic token refresh
The two features have similar names, but they work at different times. Automatic login is needed when the app is relaunched and there is no session at all, and automatic token refresh is needed while the session is alive. This guide covers automatic login.
| Feature | When it works | Handled by |
|---|---|---|
| Automatic login | The app is relaunched and there is no session | The app passes the saved credentials to the recipe to create a new session. |
| Automatic token refresh | The session is alive and only the access token has expired | The Hive Axyl SDK gets new tokens with the session's refresh token and keeps the session. |
The recipe handles only automatic login. The Hive Axyl SDK handles automatic token refresh, and the app turns this feature on once and replaces or deletes the saved values when the tokens are refreshed or the session ends. For how to turn it on, see Enable automatic access token refresh.
What the app implements
The recipe handles only the session restoration calls on the app's behalf. The app implements the following items outside the recipe.
- Saving, loading, and deleting the access token, refresh token, and Player ID
- Replacing and deleting the saved values when the tokens are refreshed and when the session ends
- Transitions between the app start screen and the login screen
- The retry policy and user-facing messages when a failure occurs
Common prerequisites
Before you start implementing, prepare the following items.
| Item to prepare | Required | Category | Where to check |
|---|---|---|---|
| Create a project | Required | Hive Console | Create a project |
| Create an App ID | Required | Hive Console | Create an App ID |
| Connect the SDK to your Unity project | Required | Hive Axyl SDK | Connect the SDK to your Unity project |
| Implement login | Required | Recipe code, App code | Guest login practical guide, Username login practical guide, Custom account login practical guide, Google login practical guide, Apple login practical guide, Google Play Games login practical guide, Steam login practical guide, X login practical guide |
The credentials that automatic login restores are created during login. If the app has no login method implemented, there are no values to save, so implement login first.
Next steps
Once you have completed the prerequisites, start Implement automatic login.