Refactored the google sign in manager

iOS
Hazim Bin Ijaz 1 month ago
parent daaa423b2d
commit bc0227971d

@ -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)

Loading…
Cancel
Save