From dc99377747a03dd0b63af68e911212187c01de9c Mon Sep 17 00:00:00 2001 From: Natalie Bunduwongse Date: Fri, 1 Mar 2024 17:31:21 +1300 Subject: [PATCH] refactor: relogin --- Assets/Shared/Scripts/UI/MainMenu.cs | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/Assets/Shared/Scripts/UI/MainMenu.cs b/Assets/Shared/Scripts/UI/MainMenu.cs index 720a89a77..6641213b5 100644 --- a/Assets/Shared/Scripts/UI/MainMenu.cs +++ b/Assets/Shared/Scripts/UI/MainMenu.cs @@ -49,23 +49,16 @@ async void OnEnable() #endif passport = await Passport.Init(clientId, environment, redirectUri, logoutUri); - // Check if the player is supposed to be logged in - if (SaveManager.Instance.IsLoggedIn) + // Check if the player is supposed to be logged in and if there are credentials saved + if (SaveManager.Instance.IsLoggedIn && await Passport.Instance.HasCredentialsSaved()) { - // Check if there are credentials saved - bool hasCredentialsSaved = await Passport.Instance.HasCredentialsSaved(); - if (hasCredentialsSaved) - { - // Try to log in using saved credentials - bool success = await Passport.Instance.Login(useCachedSession: true); - // Update the login flag - SaveManager.Instance.IsLoggedIn = success; - } - else - { - // No saved credentials to re-login the player, reset the login flag - SaveManager.Instance.IsLoggedIn = false; - } + // Try to log in using saved credentials + bool success = await Passport.Instance.Login(useCachedSession: true); + // Update the login flag + SaveManager.Instance.IsLoggedIn = success; + } else { + // No saved credentials to re-login the player, reset the login flag + SaveManager.Instance.IsLoggedIn = false; } ShowLoading(false);