Add support for deleting phone-numbers or emails
Checklist
- [x] I agree to the terms within the Auth0 Code of Conduct.
Describe the problem you'd like to have solved
With the recent addition of Connection Attributes, we would like to make a call to Management API to delete a user's phone-number or email. We can do that by sending a PATCH call to the users-endpoint (https://auth0.com/docs/api/management/v2/users/patch-users-by-id), with the payload {"phone_number":null} or {"email":null}.
However, there is no way to achieve this when using the Auth0 Go SDK, by using the function User.Update, since passing in a management.User with Email or PhoneNumber set to nil will marshal the struct to {}, which will not delete the phone/email.
Describe the ideal solution
Some suggestions:
- The
management.Usercould be changed/extended to allow explicitnullin theUser.Update-call User.Updatecould take an option (e.g.option.DeletePhoneNumber(),option.DeleteEmail()) that would set the correct payload.- A separate
User.DeletePhoneandUser.DeleteEmail(andUser.DeleteUsernamealso?) could be added, which would send the required payload.
Alternatives and current workarounds
A workaround is to use NewRequest and pass a payload that overrides the default Go marshalling, like:
type deletePhoneRequest struct{}
func (r deletePhoneRequest) MarshalJSON() ([]byte, error) {
return []byte(`{"phone_number":null}`), nil
}
This requires us to manually handle the path to the PATCH-endpoint, and handling the status-code and closing of body, etc. manually.
Additional context
No response
Hi @bendiknesbo,
Adding a method for this wouldn’t be the best approach, as we’re working on a permanent solution. It will be available soon, but we don’t have an exact timeline yet.
Thanks!
I just ran into the same problem. Please do add support for this somehow.
Another workaround, that handles constructing the path and status code, is to use the Body option:
body := management.Body([]byte(`{"email":null}`))
return client.User.Update(ctx, user.Auth0ID, nil, body)
Hi @ersimont @bendiknesbo,
We’re excited to share that v2 of the Go Auth0 SDK has just been released. It now includes setters that let you explicitly set attributes to null.
Please give it a try and let us know if it meets your needs.
Hi @bendiknesbo,
I’ll be closing this feature request since it has been fulfilled in V2.
If you still have any questions, please feel free to open a new issue.
Thanks!