68 lines
2.1 KiB
C#
68 lines
2.1 KiB
C#
using UnityEngine;
|
|
using Supabase;
|
|
using System.Threading.Tasks;
|
|
|
|
public class SupabaseEmailAuth : MonoBehaviour
|
|
{
|
|
[SerializeField] private string supabaseUrl = "https://uhmzqrqjsaqfbnvvimgy.supabase.co";
|
|
[SerializeField] private string supabaseAnonKey = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InVobXpxcnFqc2FxZmJudnZpbWd5Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3NTk5MTI1MjMsImV4cCI6MjA3NTQ4ODUyM30.VTX0zza05zNKg6M-1F3ACYxEM53dgf-dRtZOxb3uliY";
|
|
|
|
private Client client;
|
|
|
|
private async void Start()
|
|
{
|
|
//var options = new SupabaseOptions
|
|
//{
|
|
// AutoRefreshToken = true,
|
|
// AutoConnectRealtime = false
|
|
//};
|
|
|
|
//client = new Client(supabaseUrl, supabaseAnonKey, options);
|
|
//await client.InitializeAsync();
|
|
//Debug.Log("Supabase initialized");
|
|
var s = await SupabaseSecretsLoader.LoadAsync();
|
|
if (string.IsNullOrWhiteSpace(s.url) || string.IsNullOrWhiteSpace(s.anonKey))
|
|
Debug.LogError("Supabase secrets NOT embedded.");
|
|
else
|
|
Debug.Log($"Supabase URL OK: {new System.Uri(s.url).Host} (anon present: {s.anonKey.Length > 20})");
|
|
}
|
|
|
|
public async Task SignUp(string email, string password)
|
|
{
|
|
try
|
|
{
|
|
var session = await client.Auth.SignUp(email, password);
|
|
Debug.Log("Signup success: " + session?.User?.Email);
|
|
}
|
|
catch (System.Exception e)
|
|
{
|
|
Debug.LogError("Signup failed: " + e.Message);
|
|
}
|
|
}
|
|
|
|
public async Task SignIn(string email, string password)
|
|
{
|
|
try
|
|
{
|
|
var session = await client.Auth.SignIn(email, password);
|
|
Debug.Log("Signin success: " + session?.User?.Email);
|
|
}
|
|
catch (System.Exception e)
|
|
{
|
|
Debug.LogError("Signin failed: " + e.Message);
|
|
}
|
|
}
|
|
|
|
public async Task SignOut()
|
|
{
|
|
try
|
|
{
|
|
await client.Auth.SignOut();
|
|
Debug.Log("Signed out successfully.");
|
|
}
|
|
catch (System.Exception e)
|
|
{
|
|
Debug.LogError("Signout failed: " + e.Message);
|
|
}
|
|
}
|
|
} |