Question:
How to write an automation velo code which does the following: when a member signs up (condition is ok) run velo code: assign role to site member?
Product:
Wix Studio
What are you trying to achieve:
How to write an automation velo code which does the following: when a member signs up (condition is ok) run velo code: assign role to site member? I’ve built a custom sign-up.
What have you already tried:
I tried this, but didn’t work:
import { authorization } from 'wix-members-backend';
// This function is triggered when a new member is created on your site
export function wixUsers_onMemberCreated(event) {
const userId = event.user.id; // Accessing the user ID from the event object
const kliensRoleId = '05c99097-f3ee-4456-99f4-6aade2f9fece'; // The role ID for "Kliens"
const options = {
suppressAuth: false // This can be set to true if you don't want to authenticate this action separately
};
return authorization.assignRole(kliensRoleId, userId, options)
.then(() => {
console.log(`'Kliens' role successfully assigned to user with ID: ${userId}`);
})
.catch((error) => {
console.error(`Error assigning 'Kliens' role to user with ID: ${userId}: ${error}`);
});
}
Additional information:
I get the following error:
"root":{
"insertId":
"..........50bW9tusS6MfsGfa8qqvcg"
"timestamp":
"2024-04-19T18:48:27.472Z"
"labels":{
"siteUrl":
"n/a"
"revision":
"2675"
"namespace":
"Velo"
"tenantId":
"3c17964e-2da6-41ea-b1b2-d3708f941ce9"
"viewMode":
"Site"
}
"operation":{
"id":
"1713552252.098607401608136861"
"producer":
"backend"
}
"jsonPayload":{
"message":
"["Error loading function from web module backend/___spi___/automations-velo-action-provider/client_registration/client_registration.js: function 'invoke' not found"]"
}
"severity":
"ERROR"
"receiveTimestamp":
"2024-04-19T18:48:27.732Z"
}