In my website I set up a custom signup and login pages.
I want users to be able to log-in to my site only after they confirmed their email by clicking on a link in a triggered email that I sent them.
I have no problem sending the email with an approval token once the user registered thanks to a very useful explanation by @givemeawhisky here: https://www.wix.com/corvid/forum/community-discussion/register-a-user-sending-an-email-for-confirmation-1.
My problem is that whether the user is approved by clicking the email or not, he/she can still log in to the website.
Once the users click the link in the email they are redirected to a verification page with this code:
import wixLocation from 'wix-location';
import wixUsers from 'wix-users';
import {doApproval} from 'backend/register';
$w.onReady( () => {
let token = wixLocation.query.token;
doApproval(token)
.then((result) => {
if (result.approved){
wixUsers.applySessionToken(result.sessionToken);
console.log("Approved");
}
else {
console.log("Not approved!");
}
});
});
/***************************************
in backend/register
**************************************/
export function doApproval(token) {
return wixUsers.approveByToken(token)
.then((sessionToken) => {
return {sessionToken, "approved": true};
})
.catch((error) => {
return {"approved": false, "reason": error};
});
}
Is there any way for me to know if the user trying to log in was approved this way?
Thanks.