From bc0227971d2c4c97288ac8bec665c49849788df6 Mon Sep 17 00:00:00 2001 From: Hazim Bin Ijaz Date: Tue, 20 May 2025 02:25:03 +0500 Subject: [PATCH] Refactored the google sign in manager --- Assets/GoogleSigninSDK/GoogleSignInManager.cs | 49 +++++-------------- 1 file changed, 13 insertions(+), 36 deletions(-) diff --git a/Assets/GoogleSigninSDK/GoogleSignInManager.cs b/Assets/GoogleSigninSDK/GoogleSignInManager.cs index c57f632c..434a314c 100644 --- a/Assets/GoogleSigninSDK/GoogleSignInManager.cs +++ b/Assets/GoogleSigninSDK/GoogleSignInManager.cs @@ -39,7 +39,7 @@ public class GoogleSignInManager : MonoBehaviour guestLoginButton.onClick.RemoveAllListeners(); guestLoginButton.onClick.AddListener(GuestLogin); - if (PlayerPrefs.HasKey("PlayFabID") && !PlayerPrefs.HasKey("GuestMode")) + if (PlayerPrefs.HasKey("PlayFabID") && PlayerPrefs.HasKey("GoogleAuthCode")) { Debug.Log("User previously signed in with Google. Attempting silent login..."); googleSignInButton.gameObject.SetActive(false); @@ -141,43 +141,20 @@ public class GoogleSignInManager : MonoBehaviour { Debug.Log("Attempting Google Silent Sign-In..."); - configuration = new GoogleSignInConfiguration - { - WebClientId = GameConstants.Web_ClientID, - RequestEmail = true, - RequestAuthCode = true, - ForceTokenRefresh = true - }; - - // GoogleSignIn.DefaultInstance.SignIn().ContinueWith(OnGoogleSignIn); - - GoogleSignIn.DefaultInstance.SignInSilently().ContinueWith(task => + string storedAuthCode = PlayerPrefs.GetString("GoogleAuthCode"); + if (string.IsNullOrEmpty(storedAuthCode)) { - if (task.IsFaulted || task.IsCanceled) - { - Debug.LogWarning("Silent Sign-In failed. Showing login buttons."); - googleSignInButton.gameObject.SetActive(true); - googleSignInButton.interactable = true; - - guestLoginButton.gameObject.SetActive(true); - guestLoginButton.interactable = true; - return; - } - - string authCode = task.Result.AuthCode; + Debug.LogWarning("No stored auth code found. Redirecting to Google Sign-In..."); + googleSignInButton.gameObject.SetActive(true); + googleSignInButton.interactable = true; + guestLoginButton.gameObject.SetActive(true); + guestLoginButton.interactable = true; + SignInWithGoogle(); + return; + } - if (string.IsNullOrEmpty(authCode)) - { - Debug.LogError("Silent Sign-In succeeded but authCode is NULL!"); - } - else - { - Debug.Log("[Silent Sign-In] AuthCode: " + authCode); - SafePlayerPrefs.SetString("GoogleAuthCode", authCode); - PlayerPrefs.Save(); - LoginToPlayFab(authCode); - } - }); + Debug.Log("[Silent Sign-In] Using stored auth code."); + LoginToPlayFab(storedAuthCode); } private void LoginToPlayFab(string authCode)