# How to assign "admin" role, when new user signs up?

**URL:** <https://community.auth0.com/t/how-to-assign-admin-role-when-new-user-signs-up/100242>\
**Category:** Get Help\
**Tags:** user-profile, user-management\
**Created:** [February 11, 2023, 7:47am UTC](https://community.auth0.com/t/how-to-assign-admin-role-when-new-user-signs-up/100242 "2023-02-11T07:47:16Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![gerald.czifra](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/gerald.czifra/32/75301_2.png) [@gerald.czifra](https://community.auth0.com/u/gerald.czifra)\
**Post date:** [November 23, 2026, 10:57pm UTC](https://community.auth0.com/t/how-to-assign-admin-role-when-new-user-signs-up/100242/9 "2026-11-23T22:57:15Z")

</div>

Hi everyone,

We wanted to provide an update and some additional information as to how this implementation can be accomplished, in case others come across the same issue.

I understand that you wish to implement a flow where users who signup from the Auth0 Dashboard are granted the Admin role, while the access level for users created by Tenant Administrators are decided by the Admins - no role or permissions are automatically assigned.

#### Root cause

Implementing this workflow requires distinguishing between a **self-signup user** (who registers directly through your application’s Auth0 Universal Login page) and an **admin-created user** (whom an administrator invites or manually provisions via the Auth0 Dashboard / Management API).

Because both types of user creation trigger the post-registration flows, the recommended way to solve this is to use **Auth0 Actions** combined with a custom user metadata flag .

### Official Solution Strategy

1. **Admin-Created Users:** When the admin creates a user (via the Auth0 Dashboard or by calling the Management API programmatically), they must [pass a specific flag](https://community.auth0.com/t/how-to-determine-whether-user-registration-was-from-universal-login-or-api-in-actions/125379) in the user’s `user_metadata` (for example: `"created_by_admin": true`) .

2. **[Default Role Action (Post-Login):](https://support.auth0.com/center/s/article/How-do-I-add-a-default-role-to-a-new-user-on-first-login)** Create a synchronous **Post-Login Action**. This Action checks if this is the user’s very first login .

#### Step-by-Step Implementation

#### Step 1: Create a Machine-to-Machine (M2M) Application

Because assigning roles inside an Action requires communicating with Auth0’s Management API, you must authorize your action to make these edits .

1. Go to the **Auth0 Dashboard** \> **Applications** \> **Applications** and click **Create Application** ;

2. Choose **Machine to Machine Applications** and give it a name (e.g., `M2M-Action-Role-Assigner`);

3. Select the **Auth0 Management API** as the API to authorize;

4. Grant the following permission/scope:

5. Click **Authorize** and copy the **Domain** , **Client ID** , and **Client Secret** of this M2M application from its _Settings_ tab.

#### Step 2: Create the default “admin” role

1. Go to **User Management** \> **Roles** and click **+ Create Role** ;

2. Name it `admin` and write down its **Role ID** (e.g., `rol_abc123...`).

#### Step 3: Write the Post-Login Action

Using the Login flow is the most [reliable way to handle roles](https://auth0.com/blog/assign-default-role-on-sign-up-with-actions/). This is because it runs synchronously, ensuring that by the time the user completes their very first login redirect, their roles are already populated inside their issued ID/Access tokens.

1. Navigate to **Actions** \> **Library** \> click **Build Custom** ;

2. Name it `Assign Admin Role to Self-Signups`;

3. Set the **Trigger** to `Login / Post Login` and click **Create** ;

4. In the code editor, click the **Keys icon (Secrets)** on the left and define three secrets:

5. Paste the following Node.js code :

```auto
const { ManagementClient } = require('auth0');

exports.onExecutePostLogin = async (event, api) => {
  // 1. Only run this logic during the user's very first login
  const isFirstLogin = event.stats.logins_count === 1;
  
  if (!isFirstLogin) {
    return;
  }

  // 2. Check if the user was created by an admin
  const isCreatedByAdmin = event.user.user_metadata && event.user.user_metadata.created_by_admin === true;

  if (isCreatedByAdmin) {
    console.log(`User ${event.user.user_id} was created by an admin. Skipping default role assignment.`);
    return;
  }

  // 3. Initialize the Management API Client using our M2M Secrets
  const management = new ManagementClient({
    domain: event.secrets.AUTH0_DOMAIN,
    clientId: event.secrets.M2M_CLIENT_ID,
    clientSecret: event.secrets.M2M_CLIENT_SECRET,
  });

  // 4. Assign the "admin" role to the self-signup user
  const ROLE_ID = 'YOUR_ADMIN_ROLE_ID_HERE'; // Replace with your actual Admin Role ID

  try {
    await management.users.assignRoles(
      { id: event.user.user_id },
      { roles: [ROLE_ID] }
    );
    console.log(`Successfully assigned default admin role to self-signup user: ${event.user.user_id}`);
  } catch (error) {
    console.error(`Failed to assign default admin role:`, error);
  }
};

```

1. Click **Deploy** ;

2. Go to **Actions** \> **Flows** \> **Login** , find your newly created custom action under the **Custom** tab, and drag-and-drop it into your login pipeline. Click **Apply**.

### How to handle user provisioning in this setup

With the Action deployed, you must manage how users are created depending on their origin:

#### Scenario A: The User signs up themselves (Universal Login Dashboard)

The user visits your app’s signup page, inputs their details, and signs up.

- Their profile is created without any special metadata;

- When they authenticate for the first time, [`logins_count === 1`](https://support.auth0.com/center/s/article/How-logins-count-work);

- The Action finds **no** `created_by_admin: true` flag and automatically grants them the `admin` role.

#### Scenario B: The Admin creates a user manually

Whether using the **Auth0 Management API** (`POST /api/v2/users`) or custom admin panels, the admin **must explicitly pass the metadata flag** :

**Example JSON Payload for API Creation:**

```auto
{
  "email": "employee@company.com",
  "connection": "Username-Password-Authentication",
  "password": "TemporarySecurePassword123!",
  "user_metadata": {
    "created_by_admin": true
  },
  "email_verified": true
}

```

- Because `created_by_admin` is set to `true`, when this user logs in for the first time, the Action detects the flag and skips the `admin` role assignment;

- The user will only have the custom roles manually selected/assigned to them by your administrator in the Auth0 dashboard.

**Note on Auth0 UI Manual Creation:** If the admin manually creates users strictly through the **Auth0 Dashboard UI** (instead of your own admin console calling the API), they must manually go to the user’s profile settings immediately after creation, look for the **Metadata** section, and add `{"created_by_admin": true}` to the `user_metadata` before the user performs their first login.

We hope this information helped you with your implementation!

Have a great one,  
Gerald

---

_[View the full topic](https://community.auth0.com/t/how-to-assign-admin-role-when-new-user-signs-up/100242)._
