Skip to content

Commit

Permalink
feat: Add user lock, unlock & support user_lockout in instance restri…
Browse files Browse the repository at this point in the history
…ctions settings
  • Loading branch information
Mark Pitsilos committed Oct 8, 2023
1 parent 9fa920a commit b2533fd
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
24 changes: 15 additions & 9 deletions clerk/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,24 @@ func (s *InstanceService) Update(params UpdateInstanceParams) error {
}

type InstanceRestrictionsResponse struct {
Object string `json:"object"`
Allowlist bool `json:"allowlist"`
Blocklist bool `json:"blocklist"`
BlockEmailSubaddresses bool `json:"block_email_subaddresses"`
BlockDisposableEmailDomains bool `json:"block_disposable_email_domains"`
Object string `json:"object"`
Allowlist bool `json:"allowlist"`
Blocklist bool `json:"blocklist"`
BlockEmailSubaddresses bool `json:"block_email_subaddresses"`
BlockDisposableEmailDomains bool `json:"block_disposable_email_domains"`
UserLockoutEnabled bool `json:"user_lockout_enabled"`
UserLockoutMaxFailedVerificationAttempts *int64 `json:"user_lockout_max_failed_verification_attempts"`
UserLockoutLockoutDurationMinutes *int64 `json:"user_lockout_lockout_duration_minutes"`
}

type UpdateRestrictionsParams struct {
Allowlist *bool `json:"allowlist,omitempty"`
Blocklist *bool `json:"blocklist,omitempty"`
BlockEmailSubaddresses *bool `json:"block_email_subaddresses,omitempty"`
BlockDisposableEmailDomains *bool `json:"block_disposable_email_domains,omitempty"`
Allowlist *bool `json:"allowlist,omitempty"`
Blocklist *bool `json:"blocklist,omitempty"`
BlockEmailSubaddresses *bool `json:"block_email_subaddresses,omitempty"`
BlockDisposableEmailDomains *bool `json:"block_disposable_email_domains,omitempty"`
UserLockoutEnabled bool `json:"user_lockout_enabled,omitempty"`
UserLockoutMaxFailedVerificationAttempts *int64 `json:"user_lockout_max_failed_verification_attempts,omitempty"`
UserLockoutLockoutDurationMinutes *int64 `json:"user_lockout_lockout_duration_minutes,omitempty"`
}

func (s *InstanceService) UpdateRestrictions(params UpdateRestrictionsParams) (*InstanceRestrictionsResponse, error) {
Expand Down
25 changes: 25 additions & 0 deletions clerk/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b2533fd

Please sign in to comment.