# Assign roles to Regular Web App in an action

**URL:** <https://community.auth0.com/t/assign-roles-to-regular-web-app-in-an-action/90097>\
**Category:** Get Help\
**Tags:** register, nextjs, roles\
**Created:** [September 6, 2022, 8:16pm UTC](https://community.auth0.com/t/assign-roles-to-regular-web-app-in-an-action/90097 "2022-09-06T20:16:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![steffanie](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/steffanie/32/39762_2.png) [@steffanie](https://community.auth0.com/u/steffanie)\
**Post date:** [September 6, 2022, 8:16pm UTC](https://community.auth0.com/t/assign-roles-to-regular-web-app-in-an-action/90097/1 "2022-09-06T20:16:24Z")

</div>

Hello,

I would like to assign a role to a user when they register an account on our app (regular web app in auth0). I’ve seen posts on how to do this with a Machine to Machine setup and auth0 Actions, but I have errors doing this with a regular web app, not sure if it’s related to it being a RWA or not. First error had me enabled Client Credentials in the app. After that was enabled, the new error was:

> You need to create a \“client-grant\” associated to this API. See: [Auth0 Management API v2](https://auth0.com/docs/api/v2#!/Client_Grants/post_client_grants)"

Firstly, is it possible to assign roles this way with a RWA?  
Secondly, if this is possible, can you please explain the client grant portion?

The action I’m playing around with now looks like this:

```auto
exports.onExecutePostUserRegistration = async (event) => {
  const ManagementClient = require("auth0").ManagementClient;
  const management = new ManagementClient({
    domain: event.secrets.domain,
    clientId: event.secrets.clientId,
    clientSecret: event.secrets.clientSecret,
  });

  const defaultRole = { id :'some_id'};
  const data = { "users" : [event.user.user_id]};

  try {
    if(!event.user.email_verified) {
      return;
    } else {
      await management.roles.assignUsers(defaultRole, data);
    }
  } catch (e) {
    console.log(e);
  }
};

```

Thanks!

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [September 6, 2022, 9:39pm UTC](https://community.auth0.com/t/assign-roles-to-regular-web-app-in-an-action/90097/3 "2022-09-06T21:39:57Z")

</div>

Hi @steffanie,

Welcome to the Auth0 Community!

I understand that you would like to assign Roles to users using a Post-Login Action.

First, I would like to clarify that Auth0 Actions will work for any application type (e.x SPA, RWA, M2M).

Meaning that you can assign roles to a Regular Web App.

Next, I recommend going over our [How can I use the Management API in Actions?](https://community.auth0.com/t/how-can-i-use-the-management-api-in-actions/64947) FAQ which includes a working code snippet for assigning roles to users.

Please let me know if you encounter any issues getting this to work. I’d be happy to help!

Thanks.

---

<div class="post-metadata">

**Author:** ![steffanie](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/steffanie/32/39762_2.png) [@steffanie](https://community.auth0.com/u/steffanie)\
**Post date:** [September 7, 2022, 2:33am UTC](https://community.auth0.com/t/assign-roles-to-regular-web-app-in-an-action/90097/4 "2022-09-07T02:33:59Z")

</div>

> [@rueben.tiow](#):
>
> , I recommend going over our

Hi Reuben,

Thanks for the quick response! Just to clarify from the article you linked - since I want to assign roles in an Action, I must use the Management API, and the only way to use the Management API to do anything aside from updating metadata is to create a new Machine to Machine Application? Sounds simple enough 🙂 I’ll give it a shot!

(I had followed the article you linked before I posted this topic, but for some reason thought my app had to be M2M, not to create a new M2M app 😅 )

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [September 8, 2022, 12:54am UTC](https://community.auth0.com/t/assign-roles-to-regular-web-app-in-an-action/90097/5 "2022-09-08T00:54:59Z")

</div>

Hi @steffanie,

Thank you for your update!

Yes, that is correct! You will need to use either the existing Auth0 Management API or create a new M2M application and grant that application all the required permissions to use the Management API.

 ![image](https://global.discourse-cdn.com/auth0/original/3X/d/0/d0f36d0aabdc9d37f304a2696b0720c468e90d5d.png)

The latter option gives you the ability to limit certain permissions (scopes) if needed.

I hope this helps!

Thank you.

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [December 22, 2022, 10:49am UTC](https://community.auth0.com/t/assign-roles-to-regular-web-app-in-an-action/90097/6 "2022-12-22T10:49:34Z")

</div>


