9
9
Generic;
using Firebase.Extensions;
using Google;
using System.Threading.Tasks;
using UnityEngine;
using TMPro;
using Firebase.Auth;
using UnityEngine.UI;
using UnityEngine.SceneManagement; // Required for scene management
using UnityEngine.Networking;
using System.Collections;
// Initially disable the button, profile picture, and background image until login is successful
ContinueButton.gameObject.SetActive(false);
UserProfilePic.gameObject.SetActive(false);
BackgroundImage.SetActive(false); // Hide background image at start
void InitFirebase()
{
auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
}
signIn.ContinueWith(task =>
{
if (task.IsCanceled)
{
Debug.Log("Sign-in was canceled.");
}
else if (task.IsFaulted)
{
Debug.LogError("Sign-in encountered an error: " + task.Exception);
}
else
{
Debug.Log("Sign-in successful.");
GoogleSignInUser googleUser = task.Result; // Get the Google user
Credential credential =
Firebase.Auth.GoogleAuthProvider.GetCredential(googleUser.IdToken, null);
auth.SignInWithCredentialAsync(credential).ContinueWith(authTask =>
{
if (authTask.IsCanceled)
{
Debug.Log("Firebase Authentication was canceled.");
}
else if (authTask.IsFaulted)
{
Debug.LogError("Firebase Authentication encountered an error: " +
authTask.Exception);
}
else
{
FirebaseUser user = authTask.Result; // Get the Firebase user
Debug.Log("User signed in successfully: " + user.DisplayName);
// Update UI
Username.text = user.DisplayName;
UserEmail.text = user.Email;
// Enable the button, profile picture, and background image after login is successful
ContinueButton.gameObject.SetActive(true);
UserProfilePic.gameObject.SetActive(true);
BackgroundImage.SetActive(true); // Show the background image
}