hey when i want to call the LoginWithWeb3() with the HandleAuthButtonClick from the AppManager Script of the Tutorial then i get the error in the browser build. When I build the WebGL example of the youtube video, i have no problems. But in my game project the error occurs.
Here is the code I used für the HandAuthButtonCLick:
using UnityEngine;
using System.Collections.Generic;
using Cysharp.Threading.Tasks;
using TMPro;
//Moralis
using MoralisWeb3ApiSdk;
using Moralis.WebGL;
using Moralis.WebGL.Platform.Objects;
#if UNITY_WEBGL
public class AppManager : MonoBehaviour
{
public MoralisController moralisController;
public GameObject authButton;
public TextMeshProUGUI walletAddressLabel;
private async void Start()
{
if (moralisController != null)
{
await moralisController.Initialize();
}
else
{
Debug.LogError("MoralisController is null.");
return;
}
authButton.SetActive(!MoralisInterface.IsLoggedIn());
}
public async UniTask LoginWithWeb3()
{
string userAddr = "";
if (!Web3GL.IsConnected())
{
userAddr = await MoralisInterface.SetupWeb3();
}
else
{
userAddr = Web3GL.Account();
}
if (string.IsNullOrWhiteSpace(userAddr))
{
Debug.LogError("Could not login or fetch account from web3.");
}
else
{
string address = Web3GL.Account().ToLower();
string appId = MoralisInterface.GetClient().ApplicationId;
long serverTime = 0;
// Retrieve server time from Moralis Server for message signature
Dictionary<string, object> serverTimeResponse = await MoralisInterface.GetClient().Cloud.RunAsync<Dictionary<string, object>>("getServerTime", new Dictionary<string, object>());
if (serverTimeResponse == null || !serverTimeResponse.ContainsKey("dateTime") ||
!long.TryParse(serverTimeResponse["dateTime"].ToString(), out serverTime))
{
Debug.Log("Failed to retrieve server time from Moralis Server!");
}
string signMessage = $"Moralis Authentication\n\nId: {appId}:{serverTime}";
string signature = await Web3GL.Sign(signMessage);
Debug.Log($"Signature {signature} for {address} was returned.");
// Create moralis auth data from message signing response.
Dictionary<string, object> authData = new Dictionary<string, object> { { "id", address }, { "signature", signature }, { "data", signMessage } };
Debug.Log("Logging in user.");
// Attempt to login user.
MoralisUser user = await MoralisInterface.LogInAsync(authData);
if (user != null)
{
Debug.Log($"User {user.username} logged in successfully. ");
authButton.SetActive(false);
walletAddressLabel.gameObject.SetActive(true);
walletAddressLabel.text = GetWalletAddress(user);
}
else
{
Debug.Log("User login failed.");
}
}
}
private string GetWalletAddress(MoralisUser user)
{
return user.ethAddress;
}
public async void HandleAuthButtonClick()
{
await LoginWithWeb3();
}
}
#endif