Parsing error: The Keyword "let" is reserved

Hi there,
Please note that I don’t know how to code, so I am just using my logic for stuff please don’t mind me.
So I was trying to copy this code that I have found on a forum post to verify users by sending verification emails. https://www.wix.com/code/reference/wix-users-backend.html#register
The problem is that when I try to copy and paste it on the website page I am getting this error (Parsing error: The keyword “let” is reserved).
Also, I don’t understand where does the code for my submit button go?

Help will be appreciated. :slight_smile:

/*********************************
 * client-side registration code *
 *********************************/
import wixUsers from 'wix-users';
import {doRegistration} from 'backend/register';

export function button_click(event) {
  let email = // the user's email address
  let password = // the user's password
  let firstName = // the user's first name
  let lastName = // the user's last name

  doRegistration(email, password, firstName, lastName)
    .then( () => {
      console.log("Confirmation email sent.");
    } );
}

Hi, please assign to variables real values, for example:

let email = 'someEmail@gmail.com';

let - JavaScript | MDN

1 Like

Hmmmm, So this is not as easy as I thought it would be. There is more stuff to this? Isn’t there an easy way? Some example that maybe I could use without the need to code?

@salman_badshah what exactly do you want to do?
If you just need registration you can use members area without code https://support.wix.com/en/article/about-members-area

@serhiiko I want to verify a new member with email verification. You know like when you register as a new member on facebook and they send you a verification email.

@salman_badshah Well, your initial code is just for that. Can you share a link on your website?

@serhiiko www.hope-robot.com . I really don’t get it?

@salman_badshah so, you just need to assign to variables values from inputs, example:

let email = $w('#email').value; // the user's email address

https://www.wix.com/corvid/reference/$w.TextInput.html#value

@serhiiko Oh thanks let me try.

@salman_badshah there is also a way to send messages without code
https://support.wix.com/en/article/about-wix-automations

https://www.wix.com/corvid/forum/community-discussion/add-value-name-to-a-triggered-package-email

1 Like

@serhiiko Hey! So quick question. I have a submit button also. How should the code be for that? Is this right?

import wixUsers from ‘wix-users’;
import {doRegistration} from ‘backend/register’;

export function submit(event) {
let email = $w(‘#email’).value;// the user’s email address
let password = $w(‘#password’).value;// the user’s password
let firstName = $w(‘#firstName’).value;// the user’s first name
let lastName = $w(‘#lastName’).value;// the user’s last name

doRegistration(email, password, firstName, lastName)
.then( () => {
console.log(“Confirmation email sent.”);
} );
}

@salman_badshah looks good, but I can’t check it because link on your site doesn’t work anymore, also if you don’t use wixUsers you can remove first line

@serhiiko Oh I am sorry. I have published the website again. The sign up page is called Testsignup.
Ok now when I click the submit button, It just suddenly goes to the home page.
And I did not receive any email?

Ok I think I need to add a link to the verification page here? This is the back end code which I have copied for the corvid reference page. https://www.wix.com/corvid/reference/wix-users-backend.html#register

*******************************
 * backend code - register.jsw *
 *******************************/
import wixUsers from 'wix-users-backend';

export function doRegistration(email, password, firstName, lastName) {
  // register the user
  return wixUsers.register(email, password, {
    "contactInfo": {
      "firstName": firstName,
      "lastName": lastName
    }
  } )
  .then( (results) => {
    // user is now registered and pending approval
    // send a registration verification email
    wixUsers.emailUser('verifyRegistration', results.user.id, {
      "variables": {
        "name": firstName,
        "verifyLink": `http://yourdomain.com/post-register?token=${results.approvalToken}`
      }
    } );
  } );
}

export function doApproval(token) {
  // approve the user
  return wixUsers.approveByToken(token)
  // user is now active, but not logged in
  // return the session token to log in the user client-side
    .then( (sessionToken) => {
      return {sessionToken, "approved": true};
    } )
    .catch( (error) => {
      return {"approved": false, "reason": error};
    } );
}

@salman_badshah you didn’t attach the button onClick handler (right click on the button → properties → click on sign “+” on the onClick line),
also " It just suddenly goes to the home page ", because you add link to this button, so you need click on green button on screenshot and chose ‘None’

and this code

 let email = $w('#email').value;// the user's email address  let password = $w('#password').value;// the user's password  let firstName = $w('#firstName').value;// the user's first name  let lastName = $w('#lastName').value;// the user's last name    doRegistration(email, password, firstName, lastName)     .then( () => {       console.log("Confirmation email sent.");     } ); 

should be inside created function

@serhiiko How is this?

/*********************************

  • client-side registration code *
    *********************************/
    import wixUsers from ‘wix-users’;
    import {doRegistration} from ‘backend/register’;

export function submit_click(event) {
let email = $w(‘#email’);// the user’s email address
let password = $w(‘#password’);// the user’s password
let firstName = $w(‘#firstName’)// the user’s first name
let lastName = $w(‘#lastName’)// the user’s last name

doRegistration(email, password, firstName, lastName)
.then( () => {
console.log(“Confirmation email sent.”);
} );
}

@serhiiko Ok now nothing is happening when I click the Submit button?.

@salman_badshah sorry for that, I copy-paste wrong code, this one correct

/*********************************
 * client-side registration code *
 *********************************/
import wixUsers from 'wix-users';
import {doRegistration} from 'backend/register';

export function submit_click(event) {
 let email = $w('#email').value;// the user's email address
 let password = $w('#password').value;;// the user's password
 let firstName = $w('#firstName').value;// the user's first name
 let lastName = $w('#lastName').value;// the user's last name

  doRegistration(email, password, firstName, lastName)
    .then( () => {
      console.log("Confirmation email sent.");
    } );
}

@serhiiko Still nothing. It’s not working. When I click the submit button nothing happens.

@salman_badshah it looks like you still have same code