User Management Create method should return User after creation
dericcain opened this issue · 2 comments
Checklist
- I agree to the terms within the Auth0 Code of Conduct.
Describe the problem you'd like to have solved
When creating a user using the User Management Create method, it should return a user like the REST endpoint does instead of only returning an error. Since no user attributes are returned after the user is created, it is not the easiest to then fetch the newly created user. For instance, the new user would need to be fetched by their email using another method (List
maybe?).
Describe the ideal solution
Currently, the Create
method returns an error if there is one. However, it would be great if it would return the newly created user like the REST endpoint does. This would save an extra API call and some potential hacky solutions.
Alternatives and current workarounds
Once the user is created, assuming there is no error, I suppose I could use the List
or ListByEmail
methods to search for the newly created user by their email and get that user from the returned array.
Additional context
The docs show the REST endpoint returns the created user: https://auth0.com/docs/api/management/v2#!/Users/post_users
Hey @dericcain 👋
This SDK follows a population pattern where the struct passed into the function is then populated with the data returned from the API.
So for example in the following code, the first log will not log a value and the second will log only the fields populated on instantiation of user
.
After calling api.User.Create
will now return values as the ID
has been populated after creation and then the second log will contain all fields populated on creation.
user := &management.User{
Email: auth0.String("test@example.com"),
Password: auth0.String("testpassword1"),
Username: auth0.String("test"),
Connection: auth0.String("Username-Password-Authentication"),
}
// ID will not have a value
log.Printf("ID %s", user.GetID())
// Will only log the fields populated up above
log.Printf("%s", user)
err = api.User.Create(context.Background(), user)
if err != nil {
log.Fatalf("failed to create user: %+v", err)
}
// ID now has a value as it the `user` struct has been populated
log.Printf("ID %s", user.GetID())
// Will log all fields populated on creation
log.Printf("%s", user)
Wow. Genius. Thanks so much 🙏