MCPcopy Create free account
hub / github.com/auth0/auth0-cli / createUserCmd

Function createUserCmd

internal/cli/users.go:364–477  ·  view source on GitHub ↗
(cli *cli)

Source from the content-addressed store, hash-verified

362}
363
364func createUserCmd(cli *cli) *cobra.Command {
365 var inputs userInput
366
367 cmd := &cobra.Command{
368 Use: "create",
369 Args: cobra.NoArgs,
370 Short: "Create a new user",
371 Long: "Create a new user.\n\n" +
372 "To create interactively, use `auth0 users create` with no flags.\n\n" +
373 "To create non-interactively, supply the name and other information through the available flags.",
374 Example: ` auth0 users create
375 auth0 users create --name "John Doe"
376 auth0 users create --name "John Doe" --email john@example.com
377 auth0 users create --name "John Doe" --email john@example.com --connection-name "Username-Password-Authentication" --username "example"
378 auth0 users create -n "John Doe" -e john@example.com -c "Username-Password-Authentication" -u "example" --json
379 auth0 users create -n "John Doe" -e john@example.com -c "Username-Password-Authentication" -u "example" --json-compact
380 auth0 users create -n "John Doe" -e john@example.com -c "email" --json
381 auth0 users create -e john@example.com -c "email"
382 auth0 users create --phone-number +916898989898 --connection-name "sms"
383 auth0 users create -m +916898989898 -c "sms" --json
384 auth0 users create -m +916898989898 -c "sms" --json-compact`,
385 RunE: func(cmd *cobra.Command, args []string) error {
386 // Validate provided flags basis on the given connection type.
387 if cli.noInput {
388 if err := validateRequiredFlags(&inputs); err != nil {
389 return err
390 }
391 }
392
393 options, err := cli.databaseAndPasswordlessConnectionOptions(cmd.Context())
394 if err != nil {
395 return err
396 }
397
398 if err := userConnectionName.Select(cmd, &inputs.connectionName, options, nil); err != nil {
399 return err
400 }
401
402 connection, err := cli.api.Connection.ReadByName(cmd.Context(), inputs.connectionName)
403 if err != nil {
404 return fmt.Errorf("failed to find connection with name %q: %w", inputs.connectionName, err)
405 }
406
407 hasClients, err := connectionHasEnabledClients(cmd.Context(), cli.api.Connection, connection.GetID())
408 if err != nil {
409 return fmt.Errorf("failed to check enabled clients for connection %q: %w", inputs.connectionName, err)
410 }
411 if !hasClients {
412 return fmt.Errorf(
413 "failed to continue due to the connection with name %q being disabled, enable an application on this connection and try again",
414 inputs.connectionName,
415 )
416 }
417
418 var (
419 user *management.User
420 strategy = connection.GetStrategy()
421 )

Callers 1

usersCmdFunction · 0.85

Calls 15

WaitingFunction · 0.92
validateRequiredFlagsFunction · 0.85
retrieveAuth0UserDetailsFunction · 0.85
retrieveSMSUserDetailsFunction · 0.85
retrieveEmailUserDetailsFunction · 0.85
registerDetailsInfoFunction · 0.85
SelectMethod · 0.80
ErrorfMethod · 0.80
getConnReqUsernameMethod · 0.80
UserCreateMethod · 0.80

Tested by

no test coverage detected