Code Monkey home page Code Monkey logo

Comments (12)

btcgames avatar btcgames commented on June 12, 2024

signing massage has expired
This is a mistake of the developers
That's why the user can only be saved for the first 20 seconds
3

from unity-web3-game-kit.

xactant avatar xactant commented on June 12, 2024

I am not sure the error you show in the image is related.

Here is some sample code for extending a user to create a custom user. I used this and it worked for me without error:

Sample User extension code:

using Cysharp.Threading.Tasks;
using MoralisUnity;
using MoralisUnity.Platform.Objects;
using MoralisUnity.Platform.Queries;

namespace Assets.Scripts
{
    /// <summary>
    /// Create your custom user object derived from MoralisUser.
    /// Here I created a user that holds an access level and 
    /// address properties.
    /// </summary>
    public class MyCustomUser : MoralisUser
    {
        public int AccessLevel { get; set; }
        public string Street { get; set; }
        public string City { get; set; }
        public string PostalCode { get; set; }
        public string Country { get; set; }
        public string State { get; set; }

        public MyCustomUser() { }

        public MyCustomUser(MoralisUser baseUser)
        {
            base.accounts = baseUser.accounts;
            base.ACL = baseUser.ACL;
            base.authData = baseUser.authData;
            base.createdAt = baseUser.createdAt;
            base.email = baseUser.email;
            base.ethAddress = baseUser.ethAddress;
            base.objectId = baseUser.objectId;
            base.sessionToken = baseUser.sessionToken;
            base.updatedAt = baseUser.updatedAt;
            base.username = baseUser.username;
            // Necessary step to make sure the customer user is saved to
            // the _User table and not a new table.
            base.ClassName = baseUser.ClassName;
        }
    }

    /// <summary>
    /// The whole purpose of this class is to trick the MoralisQuery to 
    /// target the "_User" table
    /// </summary>
    internal class _User : MyCustomUser { }

    /// <summary>
    /// This class provides some examples showing how to create a user and 
    /// then load it at need.
    /// </summary>
    public class CustomUserServiceExample
    {
        public static async UniTask<MyCustomUser> CreateUser(MoralisUser user, int accessLevel, string street, string city, string state, string postalCode, string country)
        {
            MyCustomUser newUser = new MyCustomUser(user);
            newUser.City = city;
            newUser.State = state;
            newUser.PostalCode = postalCode;
            newUser.Country = country;
            newUser.Street = street;
            newUser.AccessLevel = accessLevel;

            await newUser.SaveAsync();

            return newUser;
        }

        /// <summary>
        /// Loads a custom user object using the normal MoralisUser
        /// as a reference.
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public static async UniTask<MyCustomUser> LoadFromUser(MoralisUser user)
        {
            return await LoadFromUser(user.objectId);
        }

        /// <summary>
        /// Loads a customer user using an objectId
        /// </summary>
        /// <param name="objectId"></param>
        /// <returns></returns>
        public static async UniTask<MyCustomUser> LoadFromUser(string objectId)
        {
            // Query using the _User object so query is against the "_User" table.
            MoralisQuery<_User> q = await Moralis.Query<_User>();

            _User user = await q.WhereEqualTo("objectId", objectId).FirstOrDefaultAsync();

            // Since _User is derived from MyCustomUser you can just return it
            // and it will be returned as a MyCustomUser.
            return user;
        }
    }
}

Here is sample code showing how I used the user extension:

   internal class Testor
    {
        public async static void TestStuff()
        {
            await CreateCustomUserTest();

            await GetCustomUserTest();
        }

        private static async UniTask CreateCustomUserTest()
        {
            MoralisUser user = await Moralis.GetUserAsync();

            await Assets.Scripts.CustomUserServiceExample.CreateUser(user, 4321, "555 My Street", "MyCity", "FL", "33809", "US");
        }

        private static async UniTask GetCustomUserTest()
        {
            MoralisUser user = await Moralis.GetUserAsync();

            Assets.Scripts.MyCustomUser myUser = await Assets.Scripts.CustomUserServiceExample.LoadFromUser(user.objectId);

            Debug.Log($"Street: {myUser.Street}, City: {myUser.City}, State: {myUser.State}, Zip: {myUser.PostalCode}");
        }
    }
    ```

from unity-web3-game-kit.

btcgames avatar btcgames commented on June 12, 2024

I am not sure the error you show in the image is related.

Here is some sample code for extending a user to create a custom user. I used this and it worked for me without error:

Sample User extension code:

using Cysharp.Threading.Tasks;
using MoralisUnity;
using MoralisUnity.Platform.Objects;
using MoralisUnity.Platform.Queries;

namespace Assets.Scripts
{
    /// <summary>
    /// Create your custom user object derived from MoralisUser.
    /// Here I created a user that holds an access level and 
    /// address properties.
    /// </summary>
    public class MyCustomUser : MoralisUser
    {
        public int AccessLevel { get; set; }
        public string Street { get; set; }
        public string City { get; set; }
        public string PostalCode { get; set; }
        public string Country { get; set; }
        public string State { get; set; }

        public MyCustomUser() { }

        public MyCustomUser(MoralisUser baseUser)
        {
            base.accounts = baseUser.accounts;
            base.ACL = baseUser.ACL;
            base.authData = baseUser.authData;
            base.createdAt = baseUser.createdAt;
            base.email = baseUser.email;
            base.ethAddress = baseUser.ethAddress;
            base.objectId = baseUser.objectId;
            base.sessionToken = baseUser.sessionToken;
            base.updatedAt = baseUser.updatedAt;
            base.username = baseUser.username;
            // Necessary step to make sure the customer user is saved to
            // the _User table and not a new table.
            base.ClassName = baseUser.ClassName;
        }
    }

    /// <summary>
    /// The whole purpose of this class is to trick the MoralisQuery to 
    /// target the "_User" table
    /// </summary>
    internal class _User : MyCustomUser { }

    /// <summary>
    /// This class provides some examples showing how to create a user and 
    /// then load it at need.
    /// </summary>
    public class CustomUserServiceExample
    {
        public static async UniTask<MyCustomUser> CreateUser(MoralisUser user, int accessLevel, string street, string city, string state, string postalCode, string country)
        {
            MyCustomUser newUser = new MyCustomUser(user);
            newUser.City = city;
            newUser.State = state;
            newUser.PostalCode = postalCode;
            newUser.Country = country;
            newUser.Street = street;
            newUser.AccessLevel = accessLevel;

            await newUser.SaveAsync();

            return newUser;
        }

        /// <summary>
        /// Loads a custom user object using the normal MoralisUser
        /// as a reference.
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public static async UniTask<MyCustomUser> LoadFromUser(MoralisUser user)
        {
            return await LoadFromUser(user.objectId);
        }

        /// <summary>
        /// Loads a customer user using an objectId
        /// </summary>
        /// <param name="objectId"></param>
        /// <returns></returns>
        public static async UniTask<MyCustomUser> LoadFromUser(string objectId)
        {
            // Query using the _User object so query is against the "_User" table.
            MoralisQuery<_User> q = await Moralis.Query<_User>();

            _User user = await q.WhereEqualTo("objectId", objectId).FirstOrDefaultAsync();

            // Since _User is derived from MyCustomUser you can just return it
            // and it will be returned as a MyCustomUser.
            return user;
        }
    }
}

Here is sample code showing how I used the user extension:

   internal class Testor
    {
        public async static void TestStuff()
        {
            await CreateCustomUserTest();

            await GetCustomUserTest();
        }

        private static async UniTask CreateCustomUserTest()
        {
            MoralisUser user = await Moralis.GetUserAsync();

            await Assets.Scripts.CustomUserServiceExample.CreateUser(user, 4321, "555 My Street", "MyCity", "FL", "33809", "US");
        }

        private static async UniTask GetCustomUserTest()
        {
            MoralisUser user = await Moralis.GetUserAsync();

            Assets.Scripts.MyCustomUser myUser = await Assets.Scripts.CustomUserServiceExample.LoadFromUser(user.objectId);

            Debug.Log($"Street: {myUser.Street}, City: {myUser.City}, State: {myUser.State}, Zip: {myUser.PostalCode}");
        }
    }
    ```

This only works for 20 seconds

from unity-web3-game-kit.

btcgames avatar btcgames commented on June 12, 2024

I need to be able to save the user at any time, not in the first 20 seconds.

from unity-web3-game-kit.

Zarbuz avatar Zarbuz commented on June 12, 2024

This issue is duplicated by #119 and #118

from unity-web3-game-kit.

btcgames avatar btcgames commented on June 12, 2024

This issue is duplicated by #119 and #118

Oh Really? Then why are you silent and doing nothing?
It would be better if you wrote a solution than such nonsense

from unity-web3-game-kit.

btcgames avatar btcgames commented on June 12, 2024

I am not sure the error you show in the image is related.

Here is some sample code for extending a user to create a custom user. I used this and it worked for me without error:

Sample User extension code:

using Cysharp.Threading.Tasks;
using MoralisUnity;
using MoralisUnity.Platform.Objects;
using MoralisUnity.Platform.Queries;

namespace Assets.Scripts
{
    /// <summary>
    /// Create your custom user object derived from MoralisUser.
    /// Here I created a user that holds an access level and 
    /// address properties.
    /// </summary>
    public class MyCustomUser : MoralisUser
    {
        public int AccessLevel { get; set; }
        public string Street { get; set; }
        public string City { get; set; }
        public string PostalCode { get; set; }
        public string Country { get; set; }
        public string State { get; set; }

        public MyCustomUser() { }

        public MyCustomUser(MoralisUser baseUser)
        {
            base.accounts = baseUser.accounts;
            base.ACL = baseUser.ACL;
            base.authData = baseUser.authData;
            base.createdAt = baseUser.createdAt;
            base.email = baseUser.email;
            base.ethAddress = baseUser.ethAddress;
            base.objectId = baseUser.objectId;
            base.sessionToken = baseUser.sessionToken;
            base.updatedAt = baseUser.updatedAt;
            base.username = baseUser.username;
            // Necessary step to make sure the customer user is saved to
            // the _User table and not a new table.
            base.ClassName = baseUser.ClassName;
        }
    }

    /// <summary>
    /// The whole purpose of this class is to trick the MoralisQuery to 
    /// target the "_User" table
    /// </summary>
    internal class _User : MyCustomUser { }

    /// <summary>
    /// This class provides some examples showing how to create a user and 
    /// then load it at need.
    /// </summary>
    public class CustomUserServiceExample
    {
        public static async UniTask<MyCustomUser> CreateUser(MoralisUser user, int accessLevel, string street, string city, string state, string postalCode, string country)
        {
            MyCustomUser newUser = new MyCustomUser(user);
            newUser.City = city;
            newUser.State = state;
            newUser.PostalCode = postalCode;
            newUser.Country = country;
            newUser.Street = street;
            newUser.AccessLevel = accessLevel;

            await newUser.SaveAsync();

            return newUser;
        }

        /// <summary>
        /// Loads a custom user object using the normal MoralisUser
        /// as a reference.
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public static async UniTask<MyCustomUser> LoadFromUser(MoralisUser user)
        {
            return await LoadFromUser(user.objectId);
        }

        /// <summary>
        /// Loads a customer user using an objectId
        /// </summary>
        /// <param name="objectId"></param>
        /// <returns></returns>
        public static async UniTask<MyCustomUser> LoadFromUser(string objectId)
        {
            // Query using the _User object so query is against the "_User" table.
            MoralisQuery<_User> q = await Moralis.Query<_User>();

            _User user = await q.WhereEqualTo("objectId", objectId).FirstOrDefaultAsync();

            // Since _User is derived from MyCustomUser you can just return it
            // and it will be returned as a MyCustomUser.
            return user;
        }
    }
}

Here is sample code showing how I used the user extension:

   internal class Testor
    {
        public async static void TestStuff()
        {
            await CreateCustomUserTest();

            await GetCustomUserTest();
        }

        private static async UniTask CreateCustomUserTest()
        {
            MoralisUser user = await Moralis.GetUserAsync();

            await Assets.Scripts.CustomUserServiceExample.CreateUser(user, 4321, "555 My Street", "MyCity", "FL", "33809", "US");
        }

        private static async UniTask GetCustomUserTest()
        {
            MoralisUser user = await Moralis.GetUserAsync();

            Assets.Scripts.MyCustomUser myUser = await Assets.Scripts.CustomUserServiceExample.LoadFromUser(user.objectId);

            Debug.Log($"Street: {myUser.Street}, City: {myUser.City}, State: {myUser.State}, Zip: {myUser.PostalCode}");
        }
    }
    ```

Where are you?

from unity-web3-game-kit.

xactant avatar xactant commented on June 12, 2024

Looking further ...

from unity-web3-game-kit.

xactant avatar xactant commented on June 12, 2024

There was a security update on the backend that now re-validates the signature everytime it is posted. I will need to add a patch for this in the Unity SDK.

For now to get past the issue, before you call user.SaveAsync(), clear the authData array. For example:

user.authData.Clear();
await user.SaveAsync();

from unity-web3-game-kit.

btcgames avatar btcgames commented on June 12, 2024

There was a security update on the backend that now re-validates the signature everytime it is posted. I will need to add a patch for this in the Unity SDK.

For now to get past the issue, before you call user.SaveAsync(), clear the authData array. For example:

user.authData.Clear();
await user.SaveAsync();

Thanks, it works.

Dear developers, please take a closer look at the problems. For a whole month you ignored the problem and said that everything was working

from unity-web3-game-kit.

xactant avatar xactant commented on June 12, 2024

Re-open as I want to incorporate a solution into the SDK ...

from unity-web3-game-kit.

stale avatar stale commented on June 12, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

from unity-web3-game-kit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.