I want to send triggered email with link to confirm registration of a member on my site.
Email trigger it’s send ok, received by the user with the link.
But link contained into mail doesn’t work. This because variable " approvalToken " is not set correctly : ( ?token= )
I think I haven’t set path correctly into the email trigger template.
Could you please give me help about link set into the mail trigger ?
You use URL path +AddVariable ? How to setup it correctly ?
I put below my code that I use into my application :
"/*******************************
* backend code - register.jsw *
*******************************/
import wixUsersBackend from 'wix-users-backend';
export function doRegistration(email, password, firstName, lastName) {
// register the user
return wixUsersBackend.register(email, password, {
"contactInfo": {
"firstName": firstName,
"lastName": lastName
}
} )
.then( (results) => {
// user is now registered and pending approval
// send a registration verification email
wixUsersBackend.emailUser('verifyRegistration', results.user.id, {
"variables": {
"name": firstName,
"verifyLink": `https://mywebsite.com/verification?token=${results.approvalToken}`
}
} );
} );
}
export function doApproval(token) {
// approve the user
return wixUsersBackend.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};
} );
}
/*********************************
* client-side registration code *
*********************************/
import wixUsersBackend from 'wix-users';
import {doRegistration} from 'backend/register';
export function button7_click_1(event) {
let firstName = $w("#input12").value // My input values
let lastName = $w("#input11").value
let email = $w("#input10").value
let password = $w("#input9").value
doRegistration(email, password)
.then( () => {
console.log("Confirmation email sent.");
} );
}
/**************************************
* client-side post-registration code *
**************************************/
import wixLocation from 'wix-location';
import wixUsersBackend from 'wix-users';
import {doApproval} from 'backend/register';
$w.onReady( () => {
// get the token from the URL
let token = wixLocation.query.token;
doApproval(token)
.then( (result) => {
if (result.approved){
// log the user in
wixUsersBackend.applySessionToken(result.sessionToken);
console.log("Approved");
}
else {
console.log("Not approved!");
}
} );
} );
And this is how i’ve set up link into email trigger :
Thanks a lot for the help !
Mattia