Skip to main content

4. Log out of Passport

💡Info
The complete code for this step can be found in the branch named step_04.

In this part of the tutorial, you will modify the existing main menu screen of the Immutable Runner game to enable the players to log out of the Passport.

By using the SaveManager.Instance.IsLoggedIn persistent flag, you can display the logout button if the player is logged in.

Assets/Shared/Scripts/UI/MainMenu.cs

async void OnEnable()
{
// omitted

ShowLoading(false);
// Show the logout button if the player is logged in
ShowLogoutButton(SaveManager.Instance.IsLoggedIn);
}

To log out of Passport completely, sessions must be cleared from both the SDK and the browser used for logging in. This requires the SDK to open a browser window to clear the latter session during logout.

If you used a specific login method in step 3, it's recommended to use the corresponding method for logging out, too. This ensures a consistent experience when the browser is opened.

Use Logout if the player logged in via Device Authorisation:

Assets/Shared/Scripts/UI/MainMenu.cs

async void OnLogoutButtonClick()
{
try
{
// Hide the 'Logout' button
ShowLogoutButton(false);
// Show loading
ShowLoading(true);

// Logout
await passport.Logout();

// Reset the login flag
SaveManager.Instance.IsLoggedIn = false;
// Successfully logged out, hide 'Logout' button
ShowLogoutButton(false);
// Reset all other values
SaveManager.Instance.Clear();
}
catch (Exception ex)
{
Debug.Log($"Failed to log out: {ex.Message}");
// Failed to logout so show 'Logout' button again
ShowLogoutButton(true);
}
// Hide loading
ShowLoading(false);
}