How to assign member role directly after signup is complete in code?

Hi, question. I’ve build a custom sign-up and want to include AssignRole in the same code. But I don’t quite understand how to connect those in one script.

Ideal result: Registered New member with assigned member role.

What I have now is:

// API Reference: https://www.wix.com/velo/reference/api-overview/introduction
// “Hello, World!” Example: https://learn-code.wix.com/en/article/1-hello-world

// $w.onReady(function () {
 // Write your JavaScript here

 // To select an element by ID use: $w("#elementID")

 // Click "Preview" to run your code
//});

///end original

import wixUsers from 'wix-users';
import wixLocation from 'wix-location';
import wixWindow from 'wix-window';
import {roles} from 'wix-users-backend';

$w.onReady(function () {
  $w('#submit').onClick( () => {
 let emails = [];
 let labels = [];  
 let location = [];
 

 
    emails.push($w('#email').value);
 

 

 // register as member using form data
    wixUsers.register($w('#email').value, $w('#password').value, {
 "contactInfo": {
 "firstName": $w('#firstName').value,
 "lastName": $w('#lastName').value,
 "emails": emails,
 "labels": labels,
 //  "height": Number($w('#height').value)
 
      }
 
      });

export function assignRole(roleId, memberId)) {
 return roles.assignRole(roleId, memberId, { suppressAuth: false })
    .then( () => {
      console.log("Role assigned to member");
    })
    .catch((error) => {
      console.log(error);
    });
//}

 
 
  });

 

 });
});
//});

Can anybody help me out with this?

Thanks

Did you manage to figure it out? I am wondering the same thing. Could you please post your solution?

Typing in…
→ Login Management <—
→ Login-System <—
→ Login System <—
→ Login-Management-System <—
→ Login Management System <—
→ Login-MGM <—
→ Login MGM <—

…into the Velo-Forum-Search and you will surely find some posts about your wished functionality. I posted numerous posts about a Login-System, which includes your wished function…

Some of the mentioned posts about ROLES and BADGES…

And there is surely even more stuff about this.

Thanks for the elaborate response. This thread was the first one I found when researching which is why I commented on it. However, I did find some of these others ones that you mentioned later on.

Thanks