Error in user registration by code

I have this code on the registration form on the site, which shows a warning when a person under 18 tries to register on the site and in this case, in addition to the message, the registration button is also hidden, but even the

 function getAge(birthdate) { 

function being called, the Wix system creates the user record. What could be the error?

Below is all the code for the registration window:

import { authentication } from 'wix-members';let emails = [];let labels = [];

$w.onReady(function () {$w('#register').onClick(() => {const password = $w('#password').value;const email = $w('#email').value;
        emails.push(email);// Check if the required fields are filledif (!$w('#firstName').value || !$w('#lastName').value || !email || !password || !$w('#birthdate').value) {$w('#warning').text = "Todos os campos são obrigatórios.";setTimeout(function () {$w('#warning').text = "";}, 10000);return;}// Check if the user is 18 years or olderconst birthdate = new Date($w('#birthdate').value);const age = getAge(birthdate);if (age < 18) {$w('#register').hide();$w('#warning').text = "Você precisa ter pelo menos 18 anos para se registrar.";setTimeout(function () {$w('#warning').text = "";}, 10000);return;} else {$w('#register').show();$w('#warning').text = "";}let options = {
            contactInfo: {
                firstName: $w('#firstName').value,
                lastName: $w('#lastName').value,
                emails: emails,
                labels: labels
            privacyStatus: 'PUBLIC'}

        authentication.register(email, password, options).then((registrationResult) => {const status = registrationResult.status;
                console.log('Member registered and logged in:', registrationResult);}).catch((error) => {
                console.error(error);});});});// Utility function to get the age from a birthdatefunction getAge(birthdate) {var today = new Date();var age = today.getFullYear() - birthdate.getFullYear();var m = today.getMonth() - birthdate.getMonth();if (m < 0 || (m === 0 && today.getDate() < birthdate.getDate())) {
        age--;}return age;}

Hi! The error could be that the function to hide the registration button is not working properly or there is an issue with the Wix system not properly handling the age validation before creating the user record. It is recommended to review the Wix documentation and forums to see if there are any known issues with this process or to consult with a Wix expert for assistance in resolving the issue.