[SOLVED] Moralis Self Hosted Server- Can not find subscription with clientId

Hey guys,

I have set up Moralis Auth on my website for my self hosted server. When I sign in, my mongodb gets updated with the user, address, etc, however it still doesn’t get updated with my event data from streams.

This is the function I am using to update the database:

export async function parseUpdate(cloneAddress: string) {
  try {
    const NewClone = Parse.Object.extend("NewClones")
    const newClone = new NewClone()
    newClone.set("cloneAddress", cloneAddress)
    console.log("DB updated!")
  } catch (e: any) {
    console.log(e)
  }

No errors show up in my console and I get the “DB Updated!” Message. An error however does show up in my Parse Dashboard error logs which says: Can not find subscription with clientId f78eb44e-7025-4c0c-911a-2acc109fe0bf subscriptionId 1

Could this be the reason my database isn’t updating, and if so, do you have any idea how I can solve it?
Thanks!

NOTE: I’m using Moralis v2 on my server and moralis v1 on the client side. Don’t know if that makes a difference.

Do you know which part of your code or function is causing this error

Before testing streams, You can also test your webhook url by sending sample data, and check if it is updating the database.

This is my validateAuthData function (from the parse-server repo provided in the docs: https://github.com/MoralisWeb3/Moralis-JS-SDK/tree/main/demos/parse-server). I don’t see any client id verification here, could it be that?

Also, I’m pretty sure my webhook url is working since I used the same url to create the stream and the database is updating with the user and session info. I’m also seeing the users on the Moralis Dashboard on the Moralis website.

function validateAuthData(authData: any) {
  const { signature, data } = authData;

  return Moralis.Auth.verify({
    message: data,
    signature,
    networkType: 'evm',
  })
    .then((result) => {
      const authenticated = result.toJSON();

      authData.chainId = result.result.chain.decimal;
      authData.nonce = authenticated.nonce;
      authData.address = result.result.address.checksum;
      authData.version = authenticated.version;
      authData.domain = authenticated.domain;
      authData.expirationTime = authenticated.expirationTime;
      authData.notBefore = authenticated.notBefore;
      authData.resources = authenticated.resources;
      authData.statement = authenticated.statement;
      authData.uri = authenticated.uri;
      authData.moralisProfileId = authenticated.profileId;
    })

    .catch(() => {
      // @ts-ignore (see note at top of file)
      throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Moralis auth failed, invalid data');
    });
}

function validateAppId() {
  return Promise.resolve();
}

EDIT: In my Parse Update function, I am importing Parse as shown below. I have never imported or initialized parse (just parse server). Could it have something to do with that?

import Parse from 'parse'
export async function parseUpdate(cAddress: any) {
  try {
    const NewClone = Parse.Object.extend("NewClones")
    const newClone = new NewClone()
    newClone.set("cloneAddress", cAddress)
    console.log("DB updated!")
  } catch (e: any) {
    console.log(e)
  }

This function is for verifying user. Since the user table is getting updated, I don’t think this function is causing the error.

Not sure if the parse function is causing the error.

You can also use the react moralis functions to update the mongo database directly.
https://v1docs.moralis.io/moralis-dapp/database/objects#save-objects

Hey @johnversus,

I believe the issue was I forgot to use ‘await’ in the parseUpdate function above and that I forgot to use await newClone.save() (I knew it was going to be something silly).

However, now that I have added this, I am getting the following error: ReferenceError: localStorage is not defined. Do you have any idea why I’m getting this? The error shows up at the await newClone.save() line.

I think this is because Parse is trying to save the item on the local storage instead of the database because it is initialised incorrectly (maybe I’m wrong).

Would love your thoughts. Thanks!

I get this error when I try to use Moralis Object: Property 'Object' does not exist on type '{ Core: MoralisCore; Auth: MoralisAuth; Streams: MoralisStreams; EvmApi: MoralisEvmApi; SolApi: MoralisSolApi; start: (providedConfig?: Partial<...> | undefined) => Promise<...>; }'

Try it with v1 sdk. It is only possible with v1 sdk.

Can I use v1 and v2 together or will I have to remove V2? Also, what do I do about Moralis.start if I use v1?

We plan to have a new tutorial this week on how to use streams with a self hosted parse server.

you can try like this.

import Moralis from "moralis";
import Moralisv1 from "moralis-v1/node";
Moralisv1.start({
  appId,
  serverUrl
})

Moralis.start({
  apiKey
})

1 Like

Worked!! This is literally the greatest web3 forum :raised_hands: :raised_hands: Thanks! @johnversus

@cryptokid looking forward to it. Mines working but it’s a little convoluted and I’m sure you guys will show a more sophisticated version of going about the set up. Hope it’s a thorough tutorial.

1 Like