Ethereum Unity3D Boilerplate Questions

Iā€™m getting a Validation failed. Please login to continue. error on my console, which might mean the user is not logged in, but in another part of the app Moralis detects that the user is logged in and hence doesnā€™t show the authenticate button.

Exact error:

  ERROR  || 2022-01-11 12:03:27
Parse error:  Validation failed. Please login to continue.

Failed running cloud function putWalletWasActiveInInterval for user undefined with:
  Input: {"signal":true}
  Error: {"message":"Validation failed. Please login to continue.","code":142}

The code that checks for the user being logged in looks like:

await MoralisInterface.Initialize(moralisAppId, moralisServerUri, new HostManifestData
{
    Identifier = appName,
    Name = appName,
    ShortVersion = buildVersion,
    Version = buildVersion
});

if (MoralisInterface.IsLoggedIn())
{
    Debug.Log(UserIsAlreadyLoggedInToMoralis);
}
else
{
    authPanel.gameObject.SetActive(true);
}

In the internals, this is what the current GetCurrentUser logic says:

public static MoralisUser GetCurrentUser<TUser>(this IServiceHub<TUser> serviceHub) where TUser : MoralisUser
{
    Task<TUser> userTask = GetCurrentUserAsync(serviceHub);

    // TODO (hallucinogen): this will without a doubt fail in Unity. How should we fix it?

    userTask.Wait();
    return userTask.Result;
}

Shouldnā€™t this be an async call?

Maybe this is the workaround. How will I find user.sessionToken?

1 Like

I want to know how I can avoid this error when running server-side code:

  Error: {"message":"Permission denied for action find on class PlayerReward.","code":119}
1 Like

@vivraan,

Do you mean documentation? If so there is the readme, and docs.moralis.io. For the C# SDK, since the majority of classes and objects are annotated you could generate documentation off of the XML comments using regular tools (Doxygen, etc.). Additionaly in code, in Visual Studio you should see hints on objects.

If I understand your second question it appears to be more toward the Javascript SDK which I would need to ask about. If I understand this properly, let me know and I will pass you question on to a JS team member who can help with that.

If I have misunderstood, sorry about that, please let me know and I can try again.

Regards,

David

Which interface are you referring to?

This is from a cloud function correct? This most likely has to do with class / object permissions. Ijust asked to be sure but the cloud function has its own set of permissions. When a table query is run in the Cloud Function, it needs to use the master key to access secured class objects. Please see the docs section on cloud functions for more information.

The validation error is also internal to the Cloud Function:

Another resource, besides the docs, for determining issues with cloud functions are your server logs.

Regards,

David

1 Like

At first glance I would agree. I need to check it out, thanks.

Iā€™m speaking of JS. docs.moralis.io is a really useful resource but it doesnā€™t contain documentation about the scripting API anywhere I check.

As for C#, the IDE pretty much reveals everything so thatā€™s not an issue.

I was referring to this post!

1 Like

I can find no mention of a solution in the Cloud Function docs for the case where I canā€™t determine if the backend is connected or not.

These are server logs which I got from moralis-admin-cli.

I donā€™t know why the server says the user is not logged in, when the login logic built in as well as the work around you mentioned which uses

        private static async Task<bool> IsLoggedInOnMoralisWorkaround() =>
            await MoralisInterface.GetClient().UserFromSession(MoralisInterface.GetUser().sessionToken) != null;

both report that the user is logged in!

Please do advise if Iā€™ve retrieved the sessionToken correctly in this case.

1 Like

This is an application / course @SamR is creating.

1 Like

Do you mind posting the validation section of your cloud function (the part with the fields etc.)
sample

}, {
	fields : ["rewardId"],
	requireUser: true
});

and the code that calls the cloud function:
example

IDictionary<string, object> pars = new Dictionary<string, object>();
pars.Add("reqardId", "1234abcdeadbeef");
RewardResponse resp = await MoralisInterface.GetClient().Cloud.RunAsync<RewardResponse>("claimReward", pars);

Thank you,

David

Cloud:

{
    fields: ["signal"],
    requireUser: true
}

Client:

protected override async UniTask<bool> SendPutRequestForActivity(bool wasActive)
{
    try
    {
        Debug.Log($"Calling Moralis Cloud Function \"{CfNamePutWalletWasActiveInInterval}\"...");
        return await MoralisInterface.GetClient().Cloud
            .RunAsync<bool>(
                CfNamePutWalletWasActiveInInterval,
                new Dictionary<string, object>
                    { ["signal"] = wasActive })
            .AsUniTask();
    }
    catch (MoralisFailureException e)
    {
#if UNITY_EDITOR || DEVELOPMENT_BUILD
        Debug.LogError($"Moralis SDK encountered an error: {e}");
#endif
        throw;
    }
}
1 Like

Thank you, I am going to try to replicate, etc. It may take me a bit to have a response.

1 Like

Oh, one more thing; is your unity instance set to build for WebGL or a different platform?

My target platform is Android.

1 Like

Are there any restrictions with the different platforms?

1 Like

I guess that would depend on what you mean by restrictions. For platforms like XBOX, PS4/5 you need special licenses from those platforms. For iOS you need to pay a $99 fee and be approved for a development account. iOS games can be developed on a PC but for iOS Unity converts the code into an Objective-C project that must be built in XCODE on a Mac.

WebGL can be slow to load larger games.

Hope this answers your question.

Regards,

David

1 Like

@vivraan,

Update - I created an empty Cloud Funcrtion:

Moralis.Cloud.define("myFunction", async (request) => {
	return true;
}, {
	fields : ["signal"],
	requireUser: true
});

The only change I made to your calling function was to remove ā€œoverrideā€ and changed the ā€œMoralisFailureExceptionā€ to an Exception.

I called the function after login and it succeeded.

So I made a menu option to call the method on button click and caught the Validation exception. Debugging through it now ā€¦

1 Like

Okay I see the cause. Summary - artifact of a fix an iOS serialization issue.

I will open an issue in Github and include a fix in the 1.0.3 release.

For now in MoralisDotNet \ Platform \ MoralisCloud.cs, line 25, change ā€œuser.SessionTokenā€ to ā€œuser.sessionTokenā€

Make the same change in Moralis.WebGL \ MoralisDotNet \ Platform \ MoralisCloud.cs.

I made the change above and the Cloud Function executed successfully.

I apologize for the frustration this has caused.

Regards,

David

1 Like

Letā€™s see if this change works!

1 Like