Sign-Up with Code


I want to make a sign-up page but only allow the user to successfully sign-up if they put the correct code in. This is my code:

import wixLocation from 'wix-location';
import authentication from 'wix-users';

$w.onReady(function () {
    // Add your code here

export function button1_click(event, $w) {
    const codeInput = $w('#codeInput');
    if (codeInput.value === 'givencode') {
        authentication.register($w("#emailInput").value, $w("#passwordInput").value)
            .then(() => {
                // Registration successful, redirect user to another page
            .catch((error) => {
                // Registration failed, show error message
                $w("#errorMessage").text = error.message;
    } else {
        // Incorrect code, show error message
        $w("#errorMessage").text = "Incorrect code.";

But when I preview it, and purposefully put the incorrect code in, it still signs up the person and does not display the error message. Am I not displaying the error code correctly?

I don’t see any code where you are checking against a required code. Are you doing this check in your backend?

if (codeInput.value === 'givencode') 

'givencode' will be the code used
1 Like

sorry, i missed that line somehow

So, if it is always evaluating to true and moving to the register function then you will want to check what you are passing as the value.

Also, if you are doing this check for a production site I would not do something like this in your page code. IT will not be secure and anyone could manipulate that code to be able to bypass your check

And finally, wix-users has reached end of life and is no longer a supported API, please use the wix-members API’s