How to check user exist or not on the database?

I need an example of how to check the availability of the user using ionic(Angular) and Parse for the database. I tried to check and learn queries but I fail to understand them.

You need something like this:

  const userQuery = new Parse.Query('User');
  userQuery.equalTo('username', params.username);
  const userResults = await userQuery.find();
  if (userResults.length > 0) {
    console.log('User exists');
  } else {
    console.log('User does not exist');
  }
1 Like

@davimacedo This code will expose the User information. So, we can just use below modified code to just check if user with input username exists or not using count.

  const userQuery = new Parse.Query('User');
  userQuery.equalTo('username', params.username);
  const userCounts = await userQuery.count();
  if (userCounts > 0) {
    console.log('User exists');
  } else {
    console.log('User does not exist');
  }
3 Likes

I am getting an error where it says, cannot find name ‘params’. Is there something I need to add?

I managed to get the answer and here is what I did: userQuery.equalTo(‘username’, this.username);

Thank you guys for your responses.

1 Like