Skip to content

Commit

Permalink
nicolas/dash 329 dapi delete ability to delete passkey (#320)
Browse files Browse the repository at this point in the history
* feat: add new method on users' client to delete passkey

* Update user/api.go

Co-authored-by: Kevin Wang <[email protected]>

* Update user/client.go

Co-authored-by: Kevin Wang <[email protected]>

---------

Co-authored-by: Kevin Wang <[email protected]>
  • Loading branch information
NicolasLopes7 and thiskevinwang authored Sep 3, 2024
1 parent 98b664a commit 240f3a5
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
5 changes: 5 additions & 0 deletions user/api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions user/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,3 +428,15 @@ func (c *Client) ListOrganizationMemberships(ctx context.Context, id string, par
err = c.Backend.Call(ctx, req, list)
return list, err
}

// DeletePasskey deletes a passkey by its identification ID.
func (c *Client) DeletePasskey(ctx context.Context, userID, identificationID string) (*clerk.DeletedResource, error) {
path, err := clerk.JoinPath(path, userID, "/passkeys", identificationID)
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
}
19 changes: 19 additions & 0 deletions user/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,3 +422,22 @@ func TestUserClientListOrganizationMemberships(t *testing.T) {
require.Equal(t, organizationID, list.OrganizationMemberships[0].Organization.ID)
require.Equal(t, userID, list.OrganizationMemberships[0].PublicUserData.UserID)
}

func TestUserClientDeletePasskey(t *testing.T) {
t.Parallel()
userID := "user_123"
passkeyIdentificationID := "idn_345"
config := &clerk.ClientConfig{}
config.HTTPClient = &http.Client{
Transport: &clerktest.RoundTripper{
T: t,
Out: json.RawMessage(fmt.Sprintf(`{"id":"%s"}`, passkeyIdentificationID)),
Method: http.MethodDelete,
Path: "/v1/users/" + userID + "/passkeys/" + passkeyIdentificationID,
},
}
client := NewClient(config)
passkey, err := client.DeletePasskey(context.Background(), userID, passkeyIdentificationID)
require.NoError(t, err)
require.Equal(t, passkeyIdentificationID, passkey.ID)
}

0 comments on commit 240f3a5

Please sign in to comment.