I’ll introduce sample code for registering a new User with an auto-generated initial password using the Auth0 API.
When registering a User via the Auth0 API, you need to set an initial password, so I used generate-password - npm.
import { ManagementClient } from 'auth0';
import { generate } from 'generate-password';
const managementClient = new ManagementClient({
domain: process.env.AUTH0_DOMAIN,
clientId: process.env.AUTH0_CLIENT_ID,
clientSecret: process.env.AUTH0_CLIENT_SECRET,
scope: process.env.AUTH0_SCOPE,
});
/**
* @see https://auth0.com/docs/connections/database/password-strength
*/
const password = generate({
length: 8,
numbers: true,
lowercase: true,
uppercase: true,
symbols: true,
strict: true,
});
return await managementClient.createUser({
email,
password,
/**
* @see https://community.auth0.com/t/combine-email-verification-password-reset/7893
*/
verify_email: false,
connection: process.env.AUTH0_DB_CONNECTION,
});
That’s all from the Gemba on introducing sample code for setting User initial passwords via Auth0 API.