Error on user checking React JS

Hi! I’m trying to check if the user exists in the database, but it says that is does although that’s not the case. I don’t understand what I’m doing wrong. This is the code:

function List()


const[friend, setFriend] = useState('')

const{user,Moralis} = useMoralis()

const userMain = user.get("username")

const {fetch,data, error, isLoading} = useMoralisQuery("Friends",q=>q.equalTo("userMain",userMain).include("friend").limit(10),[],{live:true})

const {isSaving, save} =  useNewMoralisObject('Friends')

const[wallet, setWallet] = useState('')




function saveUser(){

   const User = Moralis.Object.extend("User")

 const queryUser = new Moralis.Query(User)


 const users = queryUser.find()


    alert("User exists")

    save({friend, userMain})


    alert("User does not exist!")



this is not going to work in front end, you can do it in a cloud function and using master key, but in front end you can not access the information for all the users because there is an ACL in place for every user row.

I understand. This is actually a check by the other users when they are searching a record. The problem is that if they misspell a username, no error will be detected. What would be a good practice here? Should I create a separate table upon registration that will hold the username/wallet address? I don’t see the use of master key here since it’s not the admin who’s accessing the record.

you can write a cloud function that does that check, you can make a request to that cloud function with a username:"check_username", {username: "dfasdf}) for example, and in that cloud function you can use master key to check all the users data.

Ah, ok. That’s awesome! Thank you so much for the info!