I am currently navigating Wix at . I have successfully created a registration page that sends an email to the user with a link to confirm their account activation. Although I did manage to code the email sending process effectively, I encountered difficulty in inserting the activation link within the email message to direct users to the confirmation page for verifying their accounts. Below are the snippets of my code:
Verify Registration Page:
import wixLocation from 'wix-location';
import wixUsersBackend from 'wix-users';
import {doApproval} from 'backend/register';
$w.onReady( () => {
// fetch 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!");
}
});
});
Register Page:
import wixData from 'wix-data';
import wixWindow from 'wix-window';
import wixUsers from 'wix-users';
import wixUsersBackend from 'wix-users';
import {doRegistration} from 'backend/register';
import {sendEmail, sendEmailWithRecipient} from 'backend/email';
function sendFormData() {
let subject = `Activate your account ${$w("#firstname").value}`;
let body = `Dear ${$w("#firstname").value} ${$w("#lastname").value},
Thank you for registering on TIMLANDS, we hope you find it rewarding! Please note that your account at TIMLANDS needs to be activated.
Please click on the following URL: xxxxxxxxxx If the link above does not work, try copying and pasting it into the address bar
in your browser. This email is to confirm your registration. If you have received this email by mistake, please notify us.
TIMLANDS Team`;
const recipient = $w("#email").value;
sendEmailWithRecipient(subject, body, recipient)
.then(response => console.log(response));
sendEmail(subject, body)
.then(response => console.log(response));
}
email.jsw
import {sendWithService} from 'backend/sendGrid';
export function sendEmail(subject, body) {
const key = "SG.IIM7kezyQXm4UD........";
const sender = "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1e6d7b707a7b6c5e79737f7772307d7173">[email protected]</a>";
const recipient = "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="97e5f2f4fee7fef2f9e3d7f0faf6fefbb9f4f8fa">[email protected]</a>";
return sendWithService(key, sender, recipient, subject, body);
}
export function sendEmailWithRecipient(subject, body, recipient) {
const key = "SG.IIM7kezyQXm4UD......";
const sender = "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="daa9bfb4bebfa89abdb7bbb3b6f4b9b5b7">[email protected]</a>";
return sendWithService(key, sender, recipient, subject, body);
}
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": `http://timlands/verificationpage?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};
});
}
I am looking to integrate the activation link present in the register.jsw file into the message body displayed on the register page. Kindly refer to the image below for clarity. Any assistance would be greatly appreciated! https://i.sstatic.net/Zwtwq.png