Communication with my parse server with Moralis v2

Guys Iā€™m struggling trying to integrate Moralis v2 and let the client communicate with my Parse server database for authenticating users.

Iā€™ve followed this guide:

and

this one:

for the Parse server.

Iā€™m not sure how we can let the client talk with the server in particular here from the MetaMask tutorial:

const { account, chain } = await connectAsync({
      connector: new MetaMaskConnector(),
    });

    const { message } = await requestChallengeAsync({
      address: account,
      chainId: chain.id,
    });

    const signature = await signMessageAsync({ message });

and here from the Parse server client

const handleAuth = async () => {
  // Connect to Metamask
  const { signer, chain, account } = await connectToMetamask();

  if (!account) {
    throw new Error('No account found');
  }
  if (!chain) {
    throw new Error('No chain found');
  }

  const { message } = await requestMessage(account, chain);

  const signature = await signer.signMessage(message);

  const { user } = await verifyMessage(message, signature);

  renderUser(user);
};

How could we let the client, from the example of the MetaMask authentication guide, talk to the Parse server we just created?

I think we should use verify and verifyMessage, any example on how to call them from the client?

Thanks

You can use Moralis v1 sdk in front end if you self hosted parse server.

What are you trying to do?

Iā€™m trying to use Walleconnect for the issue reported here:

and the answer was to try to use v2.

Walletconnect is not working with moralis v1 if called by a browser that has not a Metamask extension integrated (neither from mobile), because is trying to reach speedy nodes from Moralis.

We are trying to migrate for this reason to v2

The issue is that from the documentation is not clear how we can communicate between the client and the Parse server following the guides reported above

You can make rest http requests directly for authentication after you have a way to connect to the wallet and sign a message.

Connection to the wallet should be the one with, for example, the MetaMask guide for example these parts:

const { message } = await requestChallengeAsync({
      address: account,
      chainId: chain.id,
    });

    const signature = await signMessageAsync({ message });

and this is working.

For the HTTP request you mean with axios?

Yes, you can do the authentication with axios too or with parse sdk maybe.
You can look at the request in the browser network for authentication for when it works with MetaMask and see how the http request looks like with what parameters are sent.

First thing is to get that message to sign and to sign it. Then for the authentication you will need the message and the signature and the wallet address.

Weā€™re trying now with axios with this kind of request from the signin:

 const { account, chain } = await connectAsync({ connector: new MetaMaskConnector() });

        const userData = { address: account, chain: chain.id, network: 'evm' };

        const { data } = await axios.post('/api/auth/request-message', userData, {
            headers: {
                'Content-Type': 'application/json',
            },
        });

but weā€™re getting this error:

AxiosError
code
:
ā€œERR_BAD_RESPONSEā€
config
:
{transitional: {ā€¦}, adapter: Array(2), transformRequest: Array(1), transformResponse: Array(1), timeout: 0, ā€¦}
message
:
ā€œRequest failed with status code 500ā€
name
:
ā€œAxiosErrorā€
request
:
XMLHttpRequest {onreadystatechange: null, readyState: 4, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload, ā€¦}
response
:
{data: ā€˜<style data-next-hide-fā€¦p":true,ā€œscriptLoaderā€:[]}\x3C/script>ā€™, status: 500, statusText: ā€˜Internal Server Errorā€™, headers: AxiosHeaders, config: {ā€¦}, ā€¦}
stack
:
ā€œAxiosError: Request failed with status code 500\n at settle (webpack-internal:///./node_modules/axios/lib/core/settle.js:24:12)\n at XMLHttpRequest.onloadend (webpack-internal:///./node_modules/axios/lib/adapters/xhr.js:117:66)ā€
[[Prototype]]
:
Error

Any idea about a possible reason?

Thanks

This part should work with a simple cloud function call to get the message to sign. You should be able to make it work with axios too. It will need more info in the request like the application id.
I donā€™t know why it got a 500 error. Maybe you have more logs on the server side or maybe you can add some logging in that cloud function in the server to see the parameters for example.