[SOLVED] Can't send requests to NFT API without the user connecting

Hi, long time no see, hope youā€™re doing amazing,

Iā€™ve been following documentation and forum for the related problems but

I canā€™t pass that { error: unauthorized } problem,

I did so far:

  • App ID is same both server app and client app, re-checked all details among .env files,
  • I can see my app in parse-dashboard that I installed manually at my local machine,
  • I have exported and imported all database via Studio3T, (method: mongodump, mongorestore)
  • Connection to mongodb cluster is OK
  • Connection to redis is OK
  • I converted all of my cloud functions to TS, through eslint for TS, all warnings cleared and updated
  • I turned my moralis sdk to [email protected] at client app and ensured that all files which I imported moralis updated,
  • Re-checked everything in .env file for database-app and client-app
  • removed /build and did yarn build again.
  • started the database-app by yarn dev

_
Issues:

  • I canā€™t get result from http requests to cloud functions, for example: http://localhost:1337/server/functions/getServerTime like I used to see at appId.moralis.server:2053/server/functions/

  • My production phase app canā€™t start with that server, everything is unauthorized

_

Most of the answers to the same issue in the forum was about Application ID value which is correct for both database and clientā€™s APPLICATION_ID

Where else should I check, please?

look in network tab when a request is made to see if that app id is sent there and if it is sent if it has the expected value, alternatively you can patch the parse server to ignore the app id check for cloud functions

Sorry I canā€™t see anyplace to check appid. (I mentioned some more results below the ss. )

_

Btw, client app connected to the database, after applying the patch; now the error turned into something from parse-server.

error: TypeError: Cannot read properties of undefined (reading 'type') {"code":1,"stack":"Error: TypeError: Cannot read properties of undefined (reading 'type')\n    at /home/wagmi/Projects/mymoralisapp/mymoralisapp-migrating/database-setup/node_modules/parse-server/src/Controllers/DatabaseController.js:1310:27\n    at processTicksAndRejections (node:internal/process/task_queues:96:5)"}

Here's my package.json which been used at the moment:
{
  "name": "demo-parse-server-migration",
  "version": "1.1.0",
  "main": "dist/index.js",
  "private": true,
  "dependencies": {
    "@codemirror/language": "^0.20.0",
    "@moralisweb3/common-core": "^2.14.3",
    "@moralisweb3/common-evm-utils": "^2.14.3",
    "@moralisweb3/parse-server": "2.14.3",
    "cors": "^2.8.5",
    "dotenv": "^16.0.1",
    "envalid": "7.3.1",
    "express": "^4.18.2",
    "express-rate-limit": "^6.5.1",
    "graphql": "^16.6.0",
    "graphql-ws": "^5.10.1",
    "moralis": "^2.14.3",
    "ngrok": "^4.3.3",
    "parse-server": "^5.4.0"
  },
  "devDependencies": {
    "@moralisweb3/eslint-config": "^1.0.2",
    "@types/cors": "^2.8.13",
    "@types/jest": "^29.2.5",
    "@types/node": "^18.11.18",
    "@typescript-eslint/eslint-plugin": "^5.48.2",
    "@typescript-eslint/parser": "^5.48.2",
    "axios": "^1.2.1",
    "eslint": "^8.32.0",
    "eslint-plugin-etc": "^2.0.2",
    "eslint-plugin-import": "^2.27.5",
    "jest": "^29.3.1",
    "mongodb-runner": "^4.9.0",
    "prettier": "^2.8.0",
    "ts-jest": "^29.0.4",
    "ts-node": "^10.9.1",
    "typescript": "^4.9.4"
  },
  "scripts": {
    "dev": "ts-node src/index.ts",
    "start": "node build/index.js",
    "build": "tsc",
    "lint": "eslint --ext .js,.ts .",
    "format": "prettier --write 'src/**/*.{js,ts}'",
    "dev:db-start": "mongodb-runner start",
    "dev:db-stop": "mongodb-runner stop",
    "gen:cloud": "ts-node ./scripts/generateCloudCode.ts",
    "tsc": "tsc"
  }
}

what patch did you apply?

you have to look in the payload of the request that is made to the server, it will not work if you access that url directly in the browser unless you patch the server code to skip the app id check for cloud functions

you mean this?

app.use('/server/functions/:functionName', (req, res, next) => {
  req.headers['x-parse-application-id'] = config.APPLICATION_ID;
  next();
});

I have that in index.ts and is compiled in /build.

Iā€™m using an app for detailed REST requests, can you tell me an example of running function with the right headers without getting ā€œunauthorizedā€ error?

it could be that, try to remove the quotes from the application id so that it is only the string (in case that the quotes are included somehow there)

Sorry I was waiting for your answer,

I researched but couldnā€™t get right information about how to see payload in network tab, once in a time I could see it but now canā€™t find it.

Iā€™m updating my information in here to get proper help.

Before

  1. I have an applicaton which is in production state now, itā€™s has developed in a year so thereā€™re a lot of pages and components piled up, but fundamentals are basics of moralis 1.11.0.
  2. My legacy app has react-moralis authentication just right in its githubā€™s readme documentation,
  3. Uses parse-serverā€™s native cloud functions, they are more than a dozen.

Now

  • Iā€™m using the latest package from github link from the moralis docs,
  • My legacy app connected to localhost.1337, no problem, app-id identical
  • App can reach to database through database-migration app, itā€™s alright
  • The patch (sending app id as x-parse-request) is applied as another middleware in index.ts
  • But when user tries to sign in MM I get ā€˜Moralis auth failed, invalid dataā€™ from MoralisEthAdapter

Could it be a ā€œdomain nameā€ issue?

I noticed that thereā€™s Logs folder in migration app that saved my errors and infos which is cool, Iā€™m sharing some of them:

{"code":101,"level":"error","message":"Moralis auth failed, invalid data","stack":"Error: Moralis auth failed, invalid data\n    at /home/wagmi/Projects/mymoralisapp/mymoralisapp-migrating/database-setup-new/src/auth/MoralisEthAdapter.ts:32:13\n    at runMicrotasks (<anonymous>)\n    at processTicksAndRejections (node:internal/process/task_queues:96:5)\n    at async Promise.all (index 0)","timestamp":"2023-03-13T22:51:51.776Z"}

I can give more details in PM whenever fits. I will finish this before weekend.

Try to add more logging for that auth part, like what message it tries to sign. It looks like you no longer have issues with the cloud functions.

For self hosted server you have to use the auth logic from here:
https://v1docs.moralis.io/moralis-dapp/getting-started/self-hosting-moralis-server/client-connection#note-about-authentication

probably you already know about that

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.