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

**URL:** <https://forum.wixstudio.com/t/how-to-assign-member-role-directly-after-signup-is-complete-in-code/4276>\
**Category:** Ask the community\
**Tags:** code, question\
**Created:** [January 22, 2021, 3:29pm UTC](https://forum.wixstudio.com/t/how-to-assign-member-role-directly-after-signup-is-complete-in-code/4276 "2021-01-22T15:29:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![joya](https://avatars.discourse-cdn.com/v4/letter/j/839c29/32.png) [@joya](https://forum.wixstudio.com/u/joya)\
**Post date:** [January 22, 2021, 3:29pm UTC](https://forum.wixstudio.com/t/how-to-assign-member-role-directly-after-signup-is-complete-in-code/4276/1 "2021-01-22T15:29:36Z")

</div>

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:

```javascript
// 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

---

<div class="post-metadata">

**Author:** ![alexpharaon02](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/alexpharaon02/32/7730_2.png) [@alexpharaon02](https://forum.wixstudio.com/u/alexpharaon02)\
**Post date:** [December 15, 2021, 5:52pm UTC](https://forum.wixstudio.com/t/how-to-assign-member-role-directly-after-signup-is-complete-in-code/4276/2 "2021-12-15T17:52:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [December 15, 2021, 6:03pm UTC](https://forum.wixstudio.com/t/how-to-assign-member-role-directly-after-signup-is-complete-in-code/4276/3 "2021-12-15T18:03:14Z")

</div>

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…

> **[Need to assign role based on form submission for members already in the...](https://community.wix.com/velo/forum/coding-with-velo/need-to-assign-role-based-on-form-submission-for-members-already-in-the-system)**
>
> I am trying to create a form that, upon submission, will automatically assign a specific role for the user. I am struggling to connect the Velo code and get it to actually assign the role on submission. I've attempted to follow these forum posts but...

> **[\[SOLVED\] I'm the owner/admin of the website but why is my role member? | Velo...](https://community.wix.com/velo/forum/coding-with-velo/solved-i-m-the-owner-admin-of-the-website-but-why-is-my-role-member)**
>
> I want to show/hide a custom menu based on different roles but my admin account is identified as a member. Here's how I checked the role via code:
> 
> let userRole = wixUsers.currentUser.role
> console.log(userRole)
> 
> In the console logs it shows up as...

> **[Velo by Wix: Full-Stack Web Dev | Build Professional Web Apps](https://community.wix.com/velo/forum/coding-with-velo/admin-can-no-longer-be-accessed-by-getroles/p-1/dl-61239f30761aec00150499ef)**
>
> Ask questions, get answers from the community and stay up-to-date with new features.

And there is surely even more stuff about this.

---

<div class="post-metadata">

**Author:** ![alexpharaon02](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/alexpharaon02/32/7730_2.png) [@alexpharaon02](https://forum.wixstudio.com/u/alexpharaon02)\
**Post date:** [December 18, 2021, 8:37am UTC](https://forum.wixstudio.com/t/how-to-assign-member-role-directly-after-signup-is-complete-in-code/4276/4 "2021-12-18T08:37:10Z")

</div>

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
