From b2533fd56e8f1b242b6067de27e0fb358b815c17 Mon Sep 17 00:00:00 2001 From: Mark Pitsilos Date: Fri, 6 Oct 2023 03:23:29 +0300 Subject: [PATCH] feat: Add user lock, unlock & support user_lockout in instance restrictions settings --- clerk/instances.go | 24 +++++++++++++++--------- clerk/users.go | 25 +++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/clerk/instances.go b/clerk/instances.go index 6322f41c..a92c9dc1 100644 --- a/clerk/instances.go +++ b/clerk/instances.go @@ -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) { 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