Reading a email from a collection using Velo

Question:
How to take a user inputted email and return their data from their contact information and auto fill the rest of the relevant fields?

Product:
wix Editor

What are you trying to achieve:
I have a form in which I want the client to fill in their email address. Then there are 3-9 fields that will autofill based on a previous form that was filled out. I am not using members as the person is not a member yet.

What have you already tried:
I have a backend code that seems to be finding the correct collection, and it is looking for the correct email field. The collection name and field name all match in the code. I would rather not have to do this with a collection, but have tried other ways and it has not seemed to work either.

Additional information:
This is the backend code:
import wixData from ‘wix-data’;

export async function getUserByEmail(email2) {
try {
console.log(“test1”);
const result = await wixData.query(“AllContacts”)
.eq(“email”, email2)
.find();

    if (result.items.length > 0) {
        return result.items[0]; // Return the first matching item
    } else {
        return null; // No matching item found
    }
} catch (error) {
    console.error("Error querying Users collection: ", error);
    return null;
}

}

AND this is the front end code:
// Front-end code (e.g., in a page’s code)
import { getUserByEmail } from ‘backend/crmdata’;

$w.onReady(function () {
$w(“#emailInput”).onBlur(async () => {
const email2 = $w(“#emailInput”).value;
console.log(“input email “, email2);
if (email2) {
try {
const user = await getUserByEmail(email2);
console.log(“is this working?”, user);
if (user) {
$w(”#firstName”).value = user.parentFirstName || “”;
$w(“#lastName”).value = user.parentLastName || “”;
// Autofill other fields as needed
} else {
console.log(“No user found with this email.”);
// Optionally clear the fields if no user is found
}
} catch (error) {
console.error("Error fetching user data: ", error);
}
}
});
});