Set Role On Initial User Creation / Login

Hi Auth0 Community! :waving_hand:

I’m confused about the current best practice for assigning default roles to new users. The documentation seems to point in different directions and I want to make sure I’m following the modern approach.

What I’m Trying to Achieve

  • Assign a default “user” role to every new user on signup

  • Add user roles to JWT tokens for frontend/backend authorization

  • Follow Auth0’s current best practices (not outdated methods)

My Confusion

I’ve found conflicting approaches in the docs:

:red_question_mark: Approach 1: Management API in Actions (seems outdated?)

  • Assigning Default Roles to a User on Sign up Using Auth0 Actions

  • Uses Management API calls in post-user-registration trigger

  • Problem: Getting “user does not exist” errors in test environment

:red_question_mark: Approach 2: Custom Claims Only (newer approach?)

  • Add user roles to ID and Access tokens

  • Question: But how do roles get assigned to users in the first place?

Current Issues

When testing Actions with Management API calls:

// This fails in test environment
const existingRoles = await management.users.getRoles({ id: event.user.user_id });
// Error: "The user does not exist" (404)

Questions

  1. What’s the current recommended way to assign default roles to new users?

  2. Should I use Management API in Actions or is that outdated?

  3. Are custom claims the new standard instead of actual Auth0 roles?

  4. If using custom claims in the tokens, how do I initially assign roles to users?

  5. Is the “user does not exist” error just a test environment limitation?

My Setup

  • Next.js app with @auth0/nextjs-auth0

  • Node.js typescript backend

  • Want both frontend (dashboard protection) and backend (API route protection)

  • Using Triggers

Any guidance on the modern, correct approach would be hugely appreciated! :folded_hands:

Thanks in advance!

Hi @JamesSmith

Welcome to the Auth0 Community!

Thank you for posting your question! We have an excellent Knowledge Article on setting the default role for a user during creation → Add a Default Role to a New User on First Login.

Thanks!
Dawid

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.