[SOLVED] Moralis self hosted users api

Hello,

  1. These are my parameters which i am passing in .env file
    REACT_APP_MORALIS_APPLICATION_ID =2
    REACT_APP_MORALIS_SERVER_URL =http://localhost:1337/server
    then why i am getting 404 not found??
    Request URL: http://localhost:1337/server/users
    Request Method: POST
    Status Code: 404 Not Found

  2. If i gave application id of moralis application id then it is showing
    Request Method: POST
    Status Code: 403 Forbidden

  3. Can i use “react-moralis”: “^0.2.6”, in my frontend application?

Do you have an API post route defined for /server/users?
I think there is not default api route for /server/users defined in parse-server-migration/src/index.ts file, unless you have defined something for it.

Using latest react-moralis version is recommended as it contain bug fixes.

I am using your parse-migration repository as it is.
Send me the link where and how i need to define /users?

How did you receive this error? Did you find the usage of /server/users anywhere in the docs for self-hosted servers?

You know how self hosted works and authenticate with metamask?
i am not able to call any api of self hosted server

With a self-host server, you need to update your authentication logic.

We use a cloud function called requestMessage which requests a message from the server and use it to sign the signature and verify the wallet. This is what the updated auth code looks like.

const { message } = await Moralis.Cloud.run('requestMessage', {
        address: account,
        chain: parseInt(chainId, 16),
        network: 'evm',
      });

      // Authenticate and login via parse
      await authenticate({
        signingMessage: message,
      });

You can find the complete code to handle the authentication under these docs under the react tab.

Can you give more details on how you are trying this?

Can we use self-hosted server with the version “react-moralis: 0.2.6”?

It is recommended to use the latest version, as there might be changes or bug fixes.

when i am using latest version of react-moralis then

  1. const { web3, Moralis, user } = useMoralis();
    in the ablove statement web3 is receiving null value, so how we can change this statement according to current version?

  2. Moralis.onAccountsChanged(function (address) {
    setWalletAddress(address[0]);
    });
    The above statement also send error that onAccountsChanged is not a function.
    How we can solve this?

You need to use enableWeb3 to enable and start using web3. Once you run enableWeb3() function you can start read the web3 value from useMoralis hook

const { enableWeb3 } = useMoralis();

Moralis.onAccountsChanged should work. Before using this try adding an if condition to check if Moralis value is not null. If it is not null then you should be able to access it functions.

Hi @priya1, Is this post also related to your question?

If yes, then maybe we can also mark this post as solved, if there are no further questions.

yes solved, Thank you