Question:
Front end import statements for wix members backend don’t work
Product:
Wix Editor
What are you trying to achieve:
Successfully calling myApproveByEmail and myAssignRole functions in the backend module from my front end page code.
Here is the front end page code. Note, the two import statements are currently commented out along with all other page code except for a lastName onChange handler and a buttonGo onClick handler.
import wixData from “wix-data”;
//import { myApproveByEmailFunction } from ‘backend/newSiteMember’;
//import { myAssignRoleFunction } from ‘backend/newSiteMember’;
//global variables
let wixid;
let email;
$w.onReady(function () {
//######## Register Event Handlers
//$w(“#btnGo”).onClick((event) => {
//$w(“#firstName”).focus();
//btnGo_clickHandler();
//});
});
/*
…bunch of front end code all commented out while debugging the import statements
*/
export function buttonGo_click(event) {
console.log(“Go Button clicked”);
}
export function lastName_change(event) {
console.log(“Last Name changed”);
}
On the live website, if you either fill and tab out of the lastName field OR click the buttonGo button, both event handlers fire and the console messages appear in the logs.
HOWEVER, if you simply uncomment EITHER of the two import statements, the events don’t fire. There are no errors indicated in the code and there are no errors in the live logs.
Here is the backend code in the newSiteMember.js backend file.
//Filename: backend/newSiteMember.js
import { authentication, authorization } from ‘wix-members-backend’;
export function myApproveByEmailFunction(email) {
return authentication.approveByEmail(email)
.then((sessionToken) => {
return {
sessionToken: sessionToken,
approved: true
};
})
.catch((error) => {
return {
approved: false,
reason: error
};
});
}
export function myAssignRoleFunction(wixid) {
const roleId = “dc225d03-b81b-4371-bc2c-221f1770a499”;
const memberId = wixid;
const options = {
suppressAuth: false
};
return authorization.assignRole(roleId, memberId, options)
.then(() => {
console.log(“Role assigned to member”);
})
.catch((error) => {
console.error(error);
});
}
What have you already tried:
If I run either of the functions in the backend code (by clicking the right arrow icon) in the editor, they both work just fine (the new member is approved and email sent, and a role is assigned to the new member). So, there is no problem with the newSiteMember.js code.
Additional information:
If I uncomment all of my front end code, none of it runs if either of the two backend imports are not commented out. (Nothing happens and no errors.) If they are commented out, then the front end code on the page executes.
So, this proves the problem is with the two import statements.
What is wrong with my backend import statements in my front end page code?? I am the site owner so no permission problems.