Custom wix login form

I have a piece of code here to allow user sign up or sign in with a single button: but the functions are not

import wixData from 'wix-data';
import { authentication } from 'wix-members';
import wixLocation from 'wix-location';

$w.onReady(function() {

  $w('#loginButton').onClick((Event) => {
    console.log('Button was clicked');

    // Get the user's email and password.
    let email = $w('#emailInput').value;
    let password = $w('#passwordInput').value;

    // Check if either of the input fields are empty.
    if ($w('#emailInput').value === '' || $w('#passwordInput').value === '') {
      // Show an error message.
      $w('#errorMessage').show();
      
      // Prevent the login process from being initiated.
      return;
    }

    // Check if the email address is valid.
    if (!isValidEmail(email)) {
      // Show an error message.
      $w('#errorMessage').show();
      

      // Prevent the login process from being initiated.
      return;
    }

    // Check if the email already exists.
    wixData.query("dataset1")
    .eq("email", "emailInput")
    .find()
      .then((results) => {
        if (results.items.length > 0) {
          // The email exists, so try to log the user in.
          authentication.login(email, password)
            .then((result) => {
              // The user was successfully logged in.
              wixLocation.to('https://connectarsolutions.wixsite.com/my-site-3/dashboard');
            })
            .catch((error) => {
              // The user was not successfully logged in.
              $w('#errorMessage').show();
          
            });
        } else {
          // The email does not exist, so sign the user up.
          authentication.register(email, password)
            .then((result) => {
              // Save the user's email to the dataset.
              wixData.save("dataset1", { email })
                .then((results) => {
                  console.log(results);
                })
                .catch((error) => {
                  console.log(error);
                });

              // The user was successfully registered.
              wixLocation.to('https://connectarsolutions.wixsite.com/my-site-3/dashboard');
            })
            .catch((error) => {
              // The user was not successfully registered.
              console.log(error);
            });
        }
      })
      .catch((error) => {
        // There was an error querying the dataset.
        console.log(error);
      });
  });
});

function isValidEmail(email) {
  var re = /\S+@\S+\.\S+/;
  return re.test(email);
}

I need someone with this knowledge to help debug this code

This should not be frontend code as it exposes user emails to anyone to be able to query. I’m assuming "dataset1" which contains an email field is public as it’s being queried from frontend code.

Same for email validation which should not happen in the frontend.

Can you provide a bit more detail as well?

  1. What error messages are you getting?
  2. Can you use the default Wix Members login flow? This requires no code and follows the best security practices.