diff --git a/clerk/users.go b/clerk/users.go index ca18985b..12ddcf9d 100644 --- a/clerk/users.go +++ b/clerk/users.go @@ -35,6 +35,7 @@ type User struct { UnsafeMetadata interface{} `json:"unsafe_metadata"` LastSignInAt *int64 `json:"last_sign_in_at"` Banned bool `json:"banned"` + Locked bool `json:"locked"` ExternalID *string `json:"external_id"` CreatedAt int64 `json:"created_at"` UpdatedAt int64 `json:"updated_at"` @@ -304,6 +305,30 @@ func (s *UsersService) Unban(userID string) (*User, error) { return &response, nil } +func (s *UsersService) Lock(userID string) (*User, error) { + url := fmt.Sprintf("%s/%s/lock", UsersUrl, userID) + req, _ := s.client.NewRequest(http.MethodPost, url) + + var response User + if _, err := s.client.Do(req, &response); err != nil { + return nil, err + } + + return &response, nil +} + +func (s *UsersService) Unlock(userID string) (*User, error) { + url := fmt.Sprintf("%s/%s/unlock", UsersUrl, userID) + req, _ := s.client.NewRequest(http.MethodPost, url) + + var response User + if _, err := s.client.Do(req, &response); err != nil { + return nil, err + } + + return &response, nil +} + type ListMembershipsParams struct { Limit *int Offset *int diff --git a/clerk/users_test.go b/clerk/users_test.go index ffe96bed..1764f03f 100644 --- a/clerk/users_test.go +++ b/clerk/users_test.go @@ -425,6 +425,40 @@ func TestUsersService_Unban_happyPath(t *testing.T) { assert.NoError(t, err) } +func TestUsersService_Lock_happyPath(t *testing.T) { + token := "token" + userID := "test-user-id" + + client, mux, _, teardown := setup(token) + defer teardown() + + mux.HandleFunc("/users/"+userID+"/lock", func(w http.ResponseWriter, req *http.Request) { + testHttpMethod(t, req, http.MethodPost) + testHeader(t, req, "Authorization", "Bearer "+token) + fmt.Fprint(w, dummyUserJson) + }) + + _, err := client.Users().Lock(userID) + assert.NoError(t, err) +} + +func TestUsersService_Unlock_happyPath(t *testing.T) { + token := "token" + userID := "test-user-id" + + client, mux, _, teardown := setup(token) + defer teardown() + + mux.HandleFunc("/users/"+userID+"/unlock", func(w http.ResponseWriter, req *http.Request) { + testHttpMethod(t, req, http.MethodPost) + testHeader(t, req, "Authorization", "Bearer "+token) + fmt.Fprint(w, dummyUserJson) + }) + + _, err := client.Users().Unlock(userID) + assert.NoError(t, err) +} + const dummyUserJson = `{ "birthday": "", "created_at": 1610783813, @@ -480,7 +514,8 @@ const dummyUserJson = `{ "app_id": 5 }, "last_sign_in_at": 1610783813, - "banned": false + "banned": false, + "locked": false }` const dummyUserOAuthAccessTokensJson = `[ diff --git a/tests/integration/users_test.go b/tests/integration/users_test.go index 388ed3d7..b61bcf42 100644 --- a/tests/integration/users_test.go +++ b/tests/integration/users_test.go @@ -102,6 +102,18 @@ func TestUsers(t *testing.T) { t.Fatalf("Users.Unban returned error: %v", err) } assert.False(t, updatedUser.Banned) + + updatedUser, err = client.Users().Lock(userId) + if err != nil { + t.Fatalf("Users.Ban returned error: %v", err) + } + assert.True(t, updatedUser.Locked) + + updatedUser, err = client.Users().Unlock(userId) + if err != nil { + t.Fatalf("Users.Unban returned error: %v", err) + } + assert.False(t, updatedUser.Locked) } // Should return all memberships of a user