130 lines
4.5 KiB
C#
Raw Permalink Normal View History

2025-09-19 19:43:49 +05:00
//using Firebase;
//using Firebase.Auth;
//using Firebase.Firestore;
2025-09-19 14:56:58 +05:00
using System;
using System.Threading.Tasks;
using UnityEngine;
namespace BulletHellTemplate
{
/// <summary>
/// Handles Firebase-specific authentication, storing the authenticated user,
/// and delegating data loading to FirebaseManager.
/// </summary>
public class FirebaseAuthManager : MonoBehaviour
{
2025-09-19 19:43:49 +05:00
// [Tooltip("Singleton instance for global access.")]
// public static FirebaseAuthManager Singleton;
2025-09-19 14:56:58 +05:00
2025-09-19 19:43:49 +05:00
// private bool instanceInitialized;
// private FirebaseAuth firebaseAuth;
// private FirebaseFirestore firebaseFirestore;
// private FirebaseUser currentUser;
2025-09-19 14:56:58 +05:00
2025-09-19 19:43:49 +05:00
// private void Awake()
// {
// if (Singleton == null)
// {
// Singleton = this;
// DontDestroyOnLoad(gameObject);
// }
// else
// {
// Destroy(gameObject);
// }
// }
2025-09-19 14:56:58 +05:00
2025-09-19 19:43:49 +05:00
// /// <summary>
// /// Indicates if this FirebaseAuthManager was successfully initialized.
// /// </summary>
// /// <returns>True if initialized, false otherwise.</returns>
// public bool IsInitialized()
// {
// return instanceInitialized;
// }
2025-09-19 14:56:58 +05:00
2025-09-19 19:43:49 +05:00
// /// <summary>
// /// Initializes FirebaseAuthManager with the provided FirebaseAuth and FirebaseFirestore instances.
// /// </summary>
// /// <param name="auth">FirebaseAuth instance.</param>
// /// <param name="firestore">FirebaseFirestore instance.</param>
// public void InitializeAuthBackend(FirebaseAuth auth, FirebaseFirestore firestore)
// {
// firebaseAuth = auth;
// firebaseFirestore = firestore;
// currentUser = firebaseAuth.CurrentUser;
// instanceInitialized = true;
// }
2025-09-19 14:56:58 +05:00
2025-09-19 19:43:49 +05:00
// /// <summary>
// /// Returns the current FirebaseUser, or null if none is logged in.
// /// </summary>
// public FirebaseUser GetCurrentUser()
// {
// return currentUser;
// }
2025-09-19 14:56:58 +05:00
2025-09-19 19:43:49 +05:00
// /// <summary>
// /// Logs in a user with email and password using FirebaseAuth.
// /// </summary>
// /// <param name="email">The user's email.</param>
// /// <param name="password">The user's password.</param>
// public async Task LoginWithEmailAsync(string email, string password)
// {
// if (!instanceInitialized)
// {
// throw new Exception("FirebaseAuthManager not initialized.");
// }
// await firebaseAuth.SignInWithEmailAndPasswordAsync(email, password);
// currentUser = firebaseAuth.CurrentUser;
// }
2025-09-19 14:56:58 +05:00
2025-09-19 19:43:49 +05:00
// /// <summary>
// /// Logs in a user anonymously using FirebaseAuth.
// /// </summary>
// public async Task LoginAnonymouslyAsync()
// {
// if (!instanceInitialized)
// {
// throw new Exception("FirebaseAuthManager not initialized.");
// }
// await firebaseAuth.SignInAnonymouslyAsync();
// currentUser = firebaseAuth.CurrentUser;
// }
2025-09-19 14:56:58 +05:00
2025-09-19 19:43:49 +05:00
// /// <summary>
// /// Creates a new user account with the specified email and password.
// /// </summary>
// /// <param name="email">User's email.</param>
// /// <param name="password">User's password.</param>
// public async Task CreateAccountAsync(string email, string password)
// {
// if (!instanceInitialized)
// {
// throw new Exception("FirebaseAuthManager not initialized.");
// }
// await firebaseAuth.CreateUserWithEmailAndPasswordAsync(email, password);
// currentUser = firebaseAuth.CurrentUser;
// }
2025-09-19 14:56:58 +05:00
2025-09-19 19:43:49 +05:00
// /// <summary>
// /// Calls FirebaseManager to load and synchronize the current user's data from Firestore.
// /// Returns a message describing the load result.
// /// </summary>
// public async Task<string> LoadPlayerDataAsync()
// {
// if (!instanceInitialized)
// {
// return "FirebaseAuthManager is not initialized.";
// }
// if (currentUser == null)
// {
// return "No user is currently logged in.";
// }
2025-09-19 14:56:58 +05:00
2025-09-19 19:43:49 +05:00
// string userId = currentUser.UserId;
// return await FirebaseManager.Singleton.LoadAndSyncPlayerData(userId);
// }
2025-09-19 14:56:58 +05:00
}
}