!URGENT!Simple login system query to database

Hello
I’m new to wix and with very basic knowledge in programming ( none in Javascript)

The new “Member area” doesn’t work for me simply because it’s not very customisable .
So I create database collection called “Members” in which I collect the needed information

I need onClick event where the data from textbox to be compared to certain item in the collection, but with conditional statements .

Example:

IF userinputEmail.text IS FOUND IN (“Members” , eMail) THEN
#userinputPassword.show
(afterwards compare the password with the existing one and link to dynamic page with the members ID)
else
#userinputName.show
#userinputPassword.show
#userinputEmail.show

Thank you it’s very important for me!

anyone?

I think you would be looking at something like:

export function button1_click(event, $w) {
  $w("#input1").onCustomValidation((value, reject) => {
    if (value.length === 0) {
      // this is validating the input field
      //if the input field is blank > show an error by
      //showing a hidden text or an alert or however you want
    } else {
      // if its not blank > searches the database table
      wixData.query('Name of DB_Table')
        .eq('eMail', $w('#input1').value)
        .find()
        //if it finds an email in the eMail column of your DB
        // that equals whats in the #userinputEmail input box
        // then it runs the next if loop ↓↓
        .then(results => {
            if (results.length === 0) {
              //  means email not found in DB
            } else if (results.items[0].password === $w('#userinputPassword').value) {
              // if it is, this is where you would check the value of #userinputPassword
              //  against the value of the password in the database and if they match
              // set user as logged in and make magic
            } else {
              // if they dont match give them an error
              //send them back to login
              //try again
            }
          }
        });
  });
}

I’ve just started a project using wixcode so I am still learning aswell so it would be good to get everything double checked by an expert…

on a side not…
I dont think that this method of authentication and logging in is very secure and can get complicated because you would need to write validations on all the inputs and make it so that the inputvalue (for example email) does some magic to check that its an email, then convert it to how it looks in your database

(in the code below, it checks that the email is valid and formatted correctly then gives it back to you in lowercase because email@email.com and Email@email.com are different values)

function validateEmail(email) {
var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(String(email).toLowerCase());
}

I’m also researching different ways to securely login someone via database values, so if you still need help and I figure something out I’ll post it here.