Hi all.
I need help trying to add a role to the user’s account once signed up for a new account or even on login as well please provide me the code for that kindly,
Thank you
Hi all.
I need help trying to add a role to the user’s account once signed up for a new account or even on login as well please provide me the code for that kindly,
Thank you
Can you try this code?
import { roles } from ‘wix-users-backend’ ;
import wixUsers from ‘wix-users’ ;
let email = “” // $w(‘#emailInput’).value
let password = “” // $w(‘#passwordInput’).value
let userRoleId = “” // the role id
$w . onReady ( function () {
$w ( '#registerBtn' ). onClick (() => {
wixUsers . register ( email , password )
. then (( result ) => {
let user = result . user ;
let userId = user . id
assignRole ( userRoleId , userId )
});
})
});
function assignRole ( roleId , memberId ) {
return roles . assignRole ( roleId , memberId , { suppressAuth : false })
. then (() => {
console . log ( “Role assigned to member” );
})
. catch (( error ) => {
console . log ( error );
});
}