Self-hosting your Moralis server

It’s pretty long to post it all. To be honest, aside from the request.user.get(“accounts”) not being passed to the backend Parse server by default (like it does with Moralis server), I think its the code related to reading from the MongoDb server.

See the backend cloud function code related to Mongo below:

const collection = Parse.Object.extend("Collections");
			const query = new Parse.Query(collection);
			query.equalTo(
				"contractAddress",
				requestContract.contractAddress
			);
			const collectionResult = await query.first({
				useMasterKey: true,
			});

			if (collectionResult) {
}

(obviously, there is a return etc with a bunch of logic statements etc)

did you add logging for the parameters

you can use console.log(request) to see all the parameters, request.user is not present for authenticated users?

you can also connect directly to mongo db in cloud code if needed and make the request directly that way without using Parse sdk

Hey! Did someone managed to sucessful integrate this with React Native?
My iOS app is working fine with cloud, but doing self host i’m not able to connect with any provider (like metamask).

I’ve followed the migration links but doesn’t seem to match properly the RN project.
It seems to fail every time when trying to use the walletconnect connet / auth.
Any help?

Thanks.

You can make a new topic with more details.

Done! Here is the link:

Thanks!

1 Like

Hello,

The sample Parse Server is still using Moralis.Auth service, and it needs Moralis API Key. How can I change this to a Moralis-independent code


Parse.Cloud.define('requestMessage', async ({ params }: any) => {
  const { address, chain, networkType } = params;

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

  return { message };
});

You have to change more than that code if you want to make it independent. There is also a function that validates the signature.

You can try by returning your custom message. Make sure that you take in consideration possible security issues. There is an EIP that describes that authentication.

1 Like

Hi.there. is there anyway to combine same address from using react-moralis authenticate and using signMessageAsync function?
I used same address to authenticate host parse-server, but got two different objectId.
Here’s my code
1.use react-moralis pacakge

import { useMoralis } from "react-moralis";

  const { authenticate, auth } = useMoralis();

   const { message } = await Moralis.Cloud.run("requestMessage", {
        address: account,
        // chain: parseInt(chain.id!, 16),
        chain: chain.id!,
        networkType: "evm",
      });
      let result = await authenticate({ signingMessage: message });

the result in mongo
image

and other

  const verifyMessage = (message, signature, networkType) =>
    apiPost({
      endpoint: "auth/sign-message",
      params: {
        message,
        signature,
        networkType,
      },
    });

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

Thanks for reply

What is the difference in backend between these two cases?
Like what code in backend it is called/used in these cases

Thanks for reply. for now we have lot’s of user in our DB include other infos (like avatar img). If we use auth/sign-message, the current user got a new object not origin one(the avatar image is not in this userId). we want change all front-end device(web and mobile) to call auth/sign-message api. not use react-moralis package authenticate method.

you mean that you have some users saved in the database from the past and you migrated them to current database from an old moralis server database?

yes, we want to migrate old database to our database and host parse server

did you already do that migration?
does that _auth_data_moralisEth come from that migration?

in that case, can you change it to _auth_data_moralis in that migration?

we just migrate out test sever and found that issues. I tried to change authData from dashboard, but I think it got error.
and moralisEth is from old database

yes, you can not change it from the dashboard interface, it will try to validate the data at that time and it will fail because the signature was generated long time ago

you could try to connect directly to mongo db and change it that way

or you could look in the pase server code and change that string there to make it work with moralisEth instead of moralis

not sure how to work when I change moralis to moralisEth ?
I got some error when I post a new user.

// Authenticate
  const user = await serverRequest.post<ParseUser>({
    endpoint: `/users`,
    params: {
      authData: {
        moralisEth: authData,
      },
    },
    useMasterKey: true,
  });

the error :
error MoralisError [Moralis SDK Core Error]: [C0006] Request failed, Bad Request(400): message must be present, message must contain only ASCII characters
also I found the authData is undefined when backend post a new user.

here is may repo : https://github.com/AdemKao/moralisv2-migrate-demo

not in frontend, in backend you can look where that moraliEth and moralis is used

I think the error is from backend, the verifyMessage function in authService.ts

don’t try to change the front end code, only in backend you could try to change that constant string name from moraliEth to moralis