diff --git a/user/api.go b/user/api.go index f093eec..660f3e6 100644 --- a/user/api.go +++ b/user/api.go @@ -120,6 +120,11 @@ func DeleteBackupCode(ctx context.Context, userID string) (*MultifactorAuthentic return getClient().DeleteBackupCode(ctx, userID) } +// DeleteExternalAccount deletes an external account by its ID. +func DeleteExternalAccount(ctx context.Context, params *DeleteExternalAccountParams) (*clerk.DeletedResource, error) { + return getClient().DeleteExternalAccount(ctx, params) +} + func getClient() *Client { return &Client{ Backend: clerk.GetBackend(), diff --git a/user/client.go b/user/client.go index 960af92..d9367b6 100644 --- a/user/client.go +++ b/user/client.go @@ -519,3 +519,21 @@ func (c *Client) DeleteBackupCode(ctx context.Context, userID string) (*Multifac err = c.Backend.Call(ctx, req, resource) return resource, err } + +type DeleteExternalAccountParams struct { + clerk.APIParams + UserID string `json:"-"` + ID string `json:"-"` +} + +// DeleteExternalAccount deletes an external account by its ID. +func (c *Client) DeleteExternalAccount(ctx context.Context, params *DeleteExternalAccountParams) (*clerk.DeletedResource, error) { + path, err := clerk.JoinPath(path, params.UserID, "/external_accounts", params.ID) + if err != nil { + return nil, err + } + req := clerk.NewAPIRequest(http.MethodDelete, path) + resource := &clerk.DeletedResource{} + err = c.Backend.Call(ctx, req, resource) + return resource, err +} diff --git a/user/client_test.go b/user/client_test.go index 837d7f3..b6280de 100644 --- a/user/client_test.go +++ b/user/client_test.go @@ -555,3 +555,26 @@ func TestUserClientDeleteBackupCode(t *testing.T) { require.NoError(t, err) require.Equal(t, totp.UserID, userID) } + +func TestUserClientDeleteExternalAccount(t *testing.T) { + t.Parallel() + userID := "user_123" + externalAccountID := "eac_123" + config := &clerk.ClientConfig{} + config.HTTPClient = &http.Client{ + Transport: &clerktest.RoundTripper{ + T: t, + Method: http.MethodDelete, + Out: json.RawMessage(fmt.Sprintf(`{"id":"%s","object":"external_account"}`, externalAccountID)), + Path: fmt.Sprintf("/v1/users/%s/external_accounts/%s", userID, externalAccountID), + }, + } + client := NewClient(config) + externalAccount, err := client.DeleteExternalAccount(context.Background(), &DeleteExternalAccountParams{ + UserID: userID, + ID: externalAccountID, + }) + require.NoError(t, err) + require.Equal(t, externalAccountID, externalAccount.ID) + require.Equal(t, "external_account", externalAccount.Object) +}