also nothing in console log?
can you try with a simpler cloud function (like getServerTime)? and to call it directly with a postman? (you may have to use POST)
Iâm not very familiar with making api calls in react, so I may have done it wrong.
const result = await fetch(
"http://localhost:1337/server/functions/getServerTime",
{ method: "POST" },
);
console.log(result);
results in a 403 error
Can you post your package.json?
console.log(âmessage setâ);
You arenât getting this logged? Can you log error from the try catch.
catch (error) {
console.log("err", error);
package.json:
{
"name": "gigautility",
"version": "0.2.0",
"dependencies": {
"@ant-design/icons": "^4.7.0",
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"@walletconnect/web3-provider": "^1.6.6",
"@web3auth/web3auth": "^2.1.3",
"antd": "^4.16.13",
"assert": "^2.0.0",
"crypto-browserify": "^3.12.0",
"https-browserify": "^1.0.0",
"magic-sdk": "7.0.0",
"moralis": "^1.2.3",
"moralis-v1": "^1.11.0",
"os-browserify": "^0.3.0",
"react": "^17.0.2",
"react-app-rewired": "^2.2.1",
"react-blockies": "^1.4.1",
"react-dom": "^17.0.2",
"react-moralis": "^1.2.1",
"react-query": "^3.39.1",
"react-router": "^5.2.1",
"react-router-dom": "^5.3.0",
"react-scripts": "^5.0.0",
"stream-browserify": "^3.0.0",
"stream-http": "^3.2.0",
"url": "^0.11.0",
"web-vitals": "^1.0.1",
"yarn": "^1.22.17"
},
"scripts": {
"start": "set \"GENERATE_SOURCEMAP=false\" && react-app-rewired start",
"build": "react-app-rewired build",
"test": "react-app-rewired test",
"eject": "react-app-rewired eject",
"devchain": "node Truffle/scripts/devChain.js",
"connect": "moralis-admin-cli connect-local-devchain",
"watch:events": "moralis-admin-cli add-contract",
"deploy": "node Truffle/scripts/deployContract.js",
"deploypage": "gh-pages -d build",
"clean": "npx gh-pages-clean",
"lint:check": "eslint .",
"lint:fix": "eslint --fix",
"prettier:check": "prettier --check .",
"prettier:fix": "prettier --write \"**/*.{js,jsx,ts,tsx,css,md,json,html}\" .prettierrc --config ./.prettierrc",
"format": "npm run lint:fix && npm run prettier:fix",
"prepare": "husky install"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"eslint": "^7.11.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-react": "^7.28.0",
"eslint-plugin-react-hooks": "^4.3.0",
"gh-pages": "^3.2.3",
"husky": "^7.0.0",
"lint": "^0.7.0",
"prettier": "^2.5.1"
}
}
error: err Error: You need to call Moralis.start with an applicationId before using Moralis.
Moralis is initialized in the app file, the connect button is in the header bar of the app file
or rather, Moralis is initiated in the index.js file, and isInitialized is checked in the app file
Can you try installing these versions (which are used in the migration client demo):
[email protected]
[email protected]
And remove [email protected]
.
That definitely did something. The request is going out now, and metamask is prompting for a message signing, but Iâm getting this new error
err Error: Moralis auth failed, invalid data
at handleError (RESTController.js:438:1)
Is your Parse server code the same as the demo or have you made any changes?
Can you also your Parse serverâs package.json.
server code should be the same, I dont recall making any changes
{
"name": "demo-parse-server-migration",
"version": "1.0.0",
"main": "dist/index.js",
"private": true,
"dependencies": {
"@codemirror/language": "^0.20.0",
"@moralisweb3/core": "^2.2.0",
"@types/node": "^18.7.15",
"dotenv": "^16.0.1",
"envalid": "7.3.1",
"express": "^4.18.1",
"express-rate-limit": "^6.5.1",
"graphql": "^16.6.0",
"graphql-ws": "^5.10.1",
"moralis": "^2.2.0",
"parse-server": "^5.2.5"
},
"devDependencies": {
"@moralisweb3/eslint-config": "^1.0.0",
"@typescript-eslint/eslint-plugin": "^5.12.0",
"@typescript-eslint/parser": "^5.12.0",
"axios": "^0.27.2",
"eslint": "^8.9.0",
"eslint-plugin-import": "^2.26.0",
"mongodb-runner": "^4.9.0",
"prettier": "^2.7.1",
"ts-node": "^10.9.1",
"typescript": "^4.7.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"
}
}
Can you doublecheck both .env
files for your Parse server and React app and that they more or less match (except for exact API key, Mongo/redis, etc.).
I dont recall making any changes
Can you post your Parse serverâs cloud/main.ts
code. You arenât getting any other errors in your browser console or both server terminals?
the server is getting the message request:
info: Ran cloud function requestMessage for user undefined with:
Input: {âaddressâ:â0xb03139137d06db446faa490d8a6f07d411f849c0â,âchainâ:1,ânetworkâ:âevmâ}
.env both look good
the only errors Iâm getting now is the invalid data one.
main.ts:
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-var-requires */
declare const Parse: any;
import './generated/evmApi';
import './generated/solApi';
import { requestMessage } from '../auth/authService';
Parse.Cloud.define('requestMessage', async ({ params }: any) => {
const { address, chain, network } = params;
const message = await requestMessage({
address,
chain,
network,
});
return { message };
});
Parse.Cloud.define('getPluginSpecs', () => {
// Not implemented, only excists to remove client-side errors when using the moralis-v1 package
return [];
});
Parse.Cloud.define('getServerTime', () => {
// Not implemented, only excists to remove client-side errors when using the moralis-v1 package
return null;
});
What happens if you run npm run build
for the Parse server?
same results as if I use yarn build
It looks like the message request is returning 200, but the invalid data is coming from the auth call
the sign request only says âMoralis Authenticationâ and not the message written in auth/authservice.ts
I went in and changed the domain and uri in that file to localhost and rebuilt, but Iâm still getting the same error
Can you try authenticating with a clone of the migration client - you just need to copy over your .env
file. Ideally you do the same with the parse server.
It would be easier to find out where the issue is starting from working baseline projects so we donât have to make any assumptions about how youâve set up your own server and React client.
For example, your current Parse server dependencies expects networkType
, not network
in requestMessage. On my end if I try using network
, I get type errors when trying to build.
So, this set off a whole slew of errors that should not exist and I dont understand.
First, I cloned the migration react client and ran it using my current server. everything ran smoothly, I signed the correct message with the appropriate data, but then I got this error
remembering an issue I had a while ago, I deleted the entry for my wallet in the __ethAddress table in my mongoDB. That had no effect.
Then, I created a fresh server and copied over my .env file.
ran yarn install
ran yarn build
error, saying the cors module was not found
it existed, so I ran npm i --save-dev @types/cors
(which is what the terminal suggested.
that fixed it, I was able to run yarn build
then I tried running yarn dev to start the server
error, the module âethersâ is not found
the fix for cors did not fix this
I tried manually running yarn add ethers
error, Host key verification failed.
fatal: Could not read from remote repository.
I tried copying my package.json from my current server to the new one and ran yarn install again but kept running into the same issue
For the auth is already used
error you can delete the _User
object for the wallet address youâre using from your MongoDB database. Can you see if that will work with your current custom Parse server?
I tried copying my package.json from my current server to the new one and ran yarn install again but kept running into the same issue
This would defeat of purpose of trying to get the second (demo) server working as it is by default.
I got your same errors with the latest parse-server-migration
, but installing both @types/cors
and ethers
as you mentioned fixed these on my end - I did not get the host key verification failed issue. Try deleting yarn.lock
and node_modules
and installing everything again.
I must have gotten the code for my server while you guys were still switching it around. I had no issue installing ethers today, and I got the authentication working on the react client from both the fresh server install and from my server. There was an issue where I had to change ânetworkTypeâ to ânetworkâ in the migration react client (it wouldnt let me change it on my server and I didnt want to mess with it)
However, Iâm still getting errors when trying to connect my actual website.
the message request runs fine, I get the âmessage setâ console log and I can see the api call go out and come back successfully.
the message that I sign looks like this
then the users api call fails. console shows a 404 error, network tab looks like this
console on the server logs this
error: Moralis auth failed, invalid data {"code":101,"stack":"Error: Moralis auth failed, invalid data\n at C:\\Users\\cavan\\Documents\\code\\Moralis-Server\\src\\auth\\MoralisEthAdapter.ts:32:13\n at processTicksAndRejections (node:internal/process/task_queues:96:5)\n at async Promise.all (index 0)"}
I think there is some error with the actual returning of the message to the front end, since the correct message does not show up to be signed. But Iâm not sure where that might be, since I was able to get my server to work correctly with the migration demo front end.
In the tutorial there is a specific code for authentication that is different than the code that was working with a Moralis server. You used that code?
yes, I rewrote the authentication code to use the api auth instead of what was being used for moralis hosted servers. As it stands now, I wrote out the code from the tutorial, including the button and just replaced the old connect button with it until I get everything working.
got the code from here
That Moralis Authentication message must come from somewhere else, it wouldnât be returned from the Auth API for you to sign. Check all your code to see where itâs coming from, there is probably something else being used.
somehow the âawaitâ when getting the message was deleted, so undefined was being fed as the message to sign. It seems to be working now.
Thank you everyone for your help.