diff --git a/user/api.go b/user/api.go index d07e655..56149a3 100644 --- a/user/api.go +++ b/user/api.go @@ -28,6 +28,11 @@ func UpdateProfileImage(ctx context.Context, id string, params *UpdateProfileIma return getClient().UpdateProfileImage(ctx, id, params) } +// DeleteProfileImage removes the users's profile image. +func DeleteProfileImage(ctx context.Context, id string) (*clerk.User, error) { + return getClient().DeleteProfileImage(ctx, id) +} + // UpdateMetadata updates the user's metadata by merging the // provided values with the existing ones. func UpdateMetadata(ctx context.Context, id string, params *UpdateMetadataParams) (*clerk.User, error) { diff --git a/user/client.go b/user/client.go index 3e003a2..b6cd72a 100644 --- a/user/client.go +++ b/user/client.go @@ -155,6 +155,18 @@ func (c *Client) UpdateProfileImage(ctx context.Context, id string, params *Upda return resource, err } +// DeleteProfileImage sets or replaces the user's profile image. +func (c *Client) DeleteProfileImage(ctx context.Context, id string) (*clerk.User, error) { + path, err := clerk.JoinPath(path, id, "/profile_image") + if err != nil { + return nil, err + } + req := clerk.NewAPIRequest(http.MethodDelete, path) + resource := &clerk.User{} + err = c.Backend.Call(ctx, req, resource) + return resource, err +} + type UpdateMetadataParams struct { clerk.APIParams PublicMetadata *json.RawMessage `json:"public_metadata,omitempty"` diff --git a/user/client_test.go b/user/client_test.go index 9ad7ea3..fe5602c 100644 --- a/user/client_test.go +++ b/user/client_test.go @@ -213,6 +213,24 @@ func TestUserClientUpdateProfileImage(t *testing.T) { require.Equal(t, userID, user.ID) } +func TestUserClientDeleteProfileImage(t *testing.T) { + t.Parallel() + userID := "user_123" + config := &clerk.ClientConfig{} + config.HTTPClient = &http.Client{ + Transport: &clerktest.RoundTripper{ + T: t, + Out: json.RawMessage(fmt.Sprintf(`{"id":"%s"}`, userID)), + Method: http.MethodDelete, + Path: "/v1/users/" + userID + "/profile_image", + }, + } + client := NewClient(config) + user, err := client.DeleteProfileImage(context.Background(), userID) + require.NoError(t, err) + require.Equal(t, userID, user.ID) +} + func TestUserClientUpdateMetadata(t *testing.T) { t.Parallel() id := "user_123"