Skip to main content

Connect to your client

Once you have setup your self-hosted parse-server, you can connect it to your client with version 1 of the Moralis JS SDK (moralis-v1). See https://github.com/MoralisWeb3/Moralis-JS-SDK-v1/. Additional you can also use react-moralis

You can connect to your app by providing the serverUrl and applicationId that you have set in the previous step

Example

For a client-side example that is compatible with the self-hosted parse-server see the parse-server-migration-react-client project:

Authentication

The authentication flow works a bit different when using the self-hosted server. This is because it is using the (Auth Api.

For this to work, we need tor request the message that needs to be signed from the server. An example on how to adjust for this is shown in the snippet below:

async function handleAuth(provider) {
await Moralis.enableWeb3({
throwOnError: true,
provider,
});

const { account, chainId } = Moralis;

if (!account) {
throw new Error("Connecting to chain failed, as no connected account was found");
}
if (!chainId) {
throw new Error("Connecting to chain failed, as no connected chain was found");
}

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

await Moralis.authenticate({
signingMessage: message,
throwOnError: true,
}).then((user) => {
console.log(user);
});
}

// Example
handleAuth('metamask')