[SOLVED] Server issues saving objects to custom file [used to work fine]

I thought this might be a server issue. But these two functions that worked perfectly before , all of a sudden , don’t work and I get this error :

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://q1oclm9r8ql7.grandmoralis.com:2053/server/classes/Cuser. (Reason: CORS request did not succeed).

It looks like it keeps trying to complete the request over and over as well. This is new because the code worked great before. Im starting to get scared because these weird errors keep cropping up. Please help me.

partial code:

import { useMoralis } from "react-moralis";
  const { Moralis } = useMoralis();
        async function checkThisUser( em1: string, em2: string)  {

            const Cuser = Moralis.Object.extend("Cuser");
            const query = new Moralis.Query(Cuser);
            query.equalTo("email1", em1);
            const results = await query.find();
            let goodUser = "yes";  // good = if not in the database
            for(let i = 0; i < results.length; i++){
                const object = results[i];
                if( object.get("email2") === em2 ){
                    alert("duplicate sign in - not allowed") ; 
                    goodUser = "no";
                }
            }
            return goodUser;
        }

    async function saveNewUser ( email1: string, email2:string, code1: string, code2: string ) {
       
      const Cuser = Moralis.Object.extend("Cuser");
        const cuser = new Cuser();
        cuser.set('muser', Moralis.User.current())
        cuser.set('email1', email1)
        cuser.set('email2', email2)
        cuser.set('code1', code1)
        cuser.set('code2', code2)
        let fEmail = email1 + email2;
        cuser.set('userFullEmail', fEmail)
        let response = cuser.save();
        console.log(response);
        return;
    }


//(other function )

let sv = await saveNewUser(email1, email2, code1, code2); 
let sd = await sendEmail(email1, email2, code1, code2); 
1 Like

can you try to use some logging to see if you are setting the expected parameters here:

are you authenticated when you run that code?

by default the browser will try the request again when it fails.

Here’s the thing: It says it is Authenticated… before I even try to connect to metamask. But there is no user records at all . How can it be authenticated with no user record ? Is there a way to force logout at the beginning ? SO they have to sign in and authenticate w metamask, that doesn’t say already authenticated ? Im confused just a little bit

you can force a logout with await Moralis.User.logOut();
your authentication could remain using sessions, after a successful authentication

Ya, but even if computer shut down , browser closed, when I start it up, It will say authenticated, and the user hasn’t even signed in to metamask. This is s problem. How will I do transfers, other stuff if they haven’t even signed into metamask yet ?

for doing transactions, a user doesn’t even have to be authenticated, using await Moralis.enableWeb3() will create a web3 instance that is connected to MetaMask, and if you run for example Moralis.executeFunction after that then it will pop up MetaMask to sign the transaction.

How do I run that line of code in typescript ? It gives me an error

also can you tell me what the role table is for

what is going on , is that I trashed the other server, created a new one. Now , theres; a roles table that is populated. but the user table doesn’t get populated with authentication of metamask . Also the Moralis.authenticate is kinda wacked. It says true when metamask is open no matter what the user. ,but when I go to do something like create an object, it won’t work due to maybe not being authenticted. So the authenticate with one line of code is out the window, but I keep trying and trying. To the end of my rope almost. Maybe it’s the new server, maybe its the upgrade to the new moralis sdk ,but what worked before now doesn’t work. It’s inconsistent. Maybe you guys are still in testing >? I don’t know-- keep getting these all day long
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://q1oclm9r8ql7.grandmoralis.com:2053/server/functions/getServerTime. (Reason: CORS request did not succeed)

can you try to restart that server?

I restarted it and it restarted but getting this error still and a new one (look at the last one)

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://q1oclm9r8ql7.grandmoralis.com:2053/server/functions/getPluginSpecs. (Reason: CORS request did not succeed).

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://q1oclm9r8ql7.grandmoralis.com:2053/server/functions/getPluginSpecs. (Reason: CORS request did not succeed).

Uncaught (in promise) ReferenceError: Web3 is not defined

and this one
caught (in promise) Error: XMLHttpRequest failed: “Unable to connect to the Parse API”

It was because I had added some javascript to the end of my index.html to do the metamask connect the new way. I hate it when it’s my fault. Sorry

1 Like