NextJs app - getting

Hey, I have a nextjs app configured as “regular web app” in the dashboard. I’m trying to use the management API sdk in the backend before the user login. I’m passing organization name as a parameter and trying to use the …organizations.getByName, so the user doesn’t have to go through the “enter your organization” page. The problem is that I’m not able to use the management API with my nextjs app credentials. It’s weird because is authorized and it appears as a machine to machine. I’m trying to avoid using a different set of credentials since it make sense for a nextjs app to work as m2m.

I’m using this:

var ManagementClient = require('auth0').ManagementClient;
var auth0 = new ManagementClient({
  domain: '{YOUR_ACCOUNT}',
  scope: "read:users write:users read:organizations",
  audience: 'https://{YOUR_TENANT_NAME}',
  tokenProvider: {
   enableCache: true,
   cacheTTLInSeconds: 10

And I’m getting :‘{“error”:“access_denied”,“error_description”:“Unauthorized”}’,

Also, I can’t add client credentials as grant type for this app. Any help?


Hi @german,

Welcome to the Auth0 Community!

I understand that you would like to use the Management API in your backend but encountered the “Unauthorized” error.

After my investigation, it appears that your NextJSApp is a Regular Web Application.

In this case, you will need to use the credentials of a Machine-to-Machine application with the Client Credentials grant enabled to use the Management API.

I recommend checking out Get Management API Access Tokens for Production documentation for more details.

Please let me know how this goes for you.


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