Registry / auth-security / auth0
library0.1.0jsnpmunverified

The `auth0` package is the official Node.js SDK for interacting with Auth0 services, providing robust clients for the Auth0 Management API v2, Authentication API, and UserInfo API. Currently at version 5.7.0, this library maintains an active development pace with frequent minor releases, often adding support for new Auth0 features and API endpoints. It is designed for server-side applications, offering strong TypeScript support and explicit compatibility with modern Node.js versions (specifically `^20.19.0 || ^22.12.0 || ^24.0.0`). A key differentiator is its clear separation between the current v5 API and a dedicated `/legacy` export path for maintaining compatibility with the v4.x API, facilitating smoother migrations while offering access to the latest features. It simplifies administrative tasks and user authentication flows in Node.js environments.

npm install auth0
INSTALL
IMPORT
SIG · AUTH0
A
auth0
auth-securityjavascriptv0.1.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

AuthenticationClient
import { AuthenticationClient } from 'auth0';
const { AuthenticationClient } = require('auth0');
Used for interacting with the Auth0 Authentication API. The primary export is ESM-first; avoid CommonJS 'require' in modern Node.js projects.
ManagementClient
import { ManagementClient } from 'auth0';
import ManagementClient from 'auth0';
The main client for the Auth0 Management API v2, providing administrative capabilities. It is a named export, not a default export.
UserInfoClient
import { UserInfoClient } from 'auth0';
const UserInfoClient = require('auth0').UserInfoClient;
Utilized for retrieving user profile information from an access token. As with other clients, prefer ESM imports.
ManagementClient (Legacy)
import { ManagementClient } from 'auth0/legacy';
import { ManagementClient } from 'auth0';
For compatibility with `node-auth0` v4.x API. Use this specific import path if migrating or needing to maintain legacy code behavior.

Initializes the Auth0 ManagementClient with client credentials from environment variables and fetches a list of users and specific client details from the Auth0 API.

import { ManagementClient } from 'auth0'; async function main() { const domain = process.env.AUTH0_DOMAIN ?? 'your-tenant-and-region.auth0.com'; const clientId = process.env.AUTH0_CLIENT_ID ?? 'YOUR_CLIENT_ID'; const clientSecret = process.env.AUTH0_CLIENT_SECRET ?? 'YOUR_CLIENT_SECRET'; if (!process.env.AUTH0_DOMAIN || !process.env.AUTH0_CLIENT_ID || !process.env.AUTH0_CLIENT_SECRET) { console.warn("Please set AUTH0_DOMAIN, AUTH0_CLIENT_ID, and AUTH0_CLIENT_SECRET environment variables for a real example."); } const management = new ManagementClient({ domain, clientId, clientSecret }); try { console.log("Fetching up to 5 users..."); const users = await management.users.getAll({ per_page: 5, page: 0 }); console.log(`Found ${users.length} users (showing first 5):`); users.forEach(user => console.log(`- ${user.email || user.user_id}`)); console.log("\nFetching client details for the provided client ID..."); const client = await management.clients.get({ client_id: clientId }); console.log(`Client Name: ${client.name}`); console.log(`Client ID: ${client.client_id}`); } catch (error) { console.error("An error occurred:", error); if (error instanceof Error) { console.error("Error message:", error.message); // console.error("Stack trace:", error.stack); // Uncomment for full stack trace } if (typeof error === 'object' && error !== null && 'statusCode' in error) { console.error(`Status Code: ${error.statusCode}`); } } } main();
Debug
Known issues
breakingThe transition from `node-auth0` v4.x to v5.x introduced significant API changes. Code written for v4.x will likely break without modification.
fix
Either refactor your code to use the new v5 API surface or import `ManagementClient` and `AuthenticationClient` from the dedicated `auth0/legacy` path to maintain v4.x compatibility.
affects: >=5.0.0
breakingThis library has strict Node.js engine requirements, dropping support for older LTS versions. The package explicitly requires Node.js `^20.19.0 || ^22.12.0 || ^24.0.0`.
fix
Ensure your Node.js environment meets the minimum requirements. Upgrade Node.js to one of the supported versions if you encounter engine compatibility errors.
affects: >=5.0.0
gotchaWhen initializing the `ManagementClient`, it's generally more robust to use `clientId` and `clientSecret` for client credentials flow instead of directly providing a static `token`. Using client credentials allows the SDK to handle token issuance and refresh automatically.
fix
Prioritize initializing `ManagementClient` with `clientId` and `clientSecret` for server-side applications to leverage automatic token management and refresh capabilities, reducing the risk of expired tokens.
affects: *
gotchaAuth0's Management API has rate limits. Frequent or high-volume API calls without proper handling can lead to `429 Too Many Requests` errors.
fix
Implement robust error handling with retry logic and exponential backoff for API calls. Review Auth0's rate limit documentation and optimize your application's API usage patterns.
affects: *
Errors
Common errors & fixes
TypeError: Cannot destructure property 'ManagementClient' of 'require(...)' as it is undefined.
Attempting to use CommonJS `require()` syntax with `auth0` package which is primarily an ESM module in modern Node.js environments.
fix
Switch to ES Module `import { ManagementClient } from 'auth0';` syntax. If targeting the legacy v4 API, use `const { ManagementClient } = require('auth0/legacy');`.
ERR_REQUIRE_ESM: require() of ES Module ...auth0/dist/index.js not supported.
Your Node.js project is running in CommonJS mode (e.g., no `"type": "module"` in `package.json`), and you're trying to `require()` an ESM-only package.
fix
Configure your project to use ES Modules by adding `"type": "module"` to your `package.json` and updating your source files to use `import`/`export` syntax. Alternatively, ensure your Node.js version supports seamless ESM/CJS interop or check for a specific CommonJS entry point if available.
Auth0Error: Unauthorized: Bad credentials (or Invalid Token / Missing scopes)
The Auth0 domain, client ID, client secret, or API token provided during client initialization is incorrect, expired, or lacks the necessary permissions (scopes) for the requested operation.
fix
Verify that your Auth0 application credentials (client ID, client secret) are correct. For `ManagementClient`, ensure your API token is valid, unexpired, and has all required Management API scopes configured (e.g., `read:users`, `update:users`). Generate a new token if necessary.
Upgrade
Version history
0.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
41 hits · last 30 days
node
34
OpenAI (training)
1
Resources
auth0 — npm install auth0 · libregistry