@@ -57,11 +57,15 @@ def self.find(id, user_class = nil)
5757 )
5858 user = new ( user_class : user_class )
5959 user . id = result . username
60- user . email = result . user_attributes . find { | attribute | attribute [ :name ] == ' email' } [ :value ]
61- user . phone = result . user_attributes . find { | attribute | attribute [ :name ] == ' phone_number' } &. dig ( :value )
60+ user . email = extract_cognito_attribute ( result . user_attributes , : email)
61+ user . phone = extract_cognito_attribute ( result . user_attributes , : phone_number)
6262 user
6363 end
6464
65+ def self . all
66+ cognito_client . list_users ( user_pool_id : CognitoRails ::Config . aws_user_pool_id )
67+ end
68+
6569 # @param attributes [Hash]
6670 # @option attributes [String] :email
6771 # @option attributes [String] :password
@@ -138,6 +142,18 @@ def destroy!
138142 destroy || ( raise ActiveRecord ::RecordInvalid , self )
139143 end
140144
145+ # @return [Aws::CognitoIdentityProvider::Client]
146+ # @raise [RuntimeError]
147+ def self . cognito_client
148+ @cognito_client ||= Aws ::CognitoIdentityProvider ::Client . new (
149+ { region : CognitoRails ::Config . aws_region } . merge ( CognitoRails ::Config . aws_client_credentials )
150+ )
151+ end
152+
153+ def self . extract_cognito_attribute ( attributes , column )
154+ attributes . find { |attribute | attribute [ :name ] == column . to_s } &.dig ( :value )
155+ end
156+
141157 private
142158
143159 # @return [Aws::CognitoIdentityProvider::Client]
@@ -155,14 +171,6 @@ def verify_phone?
155171 user_class . _cognito_verify_phone
156172 end
157173
158- # @return [Aws::CognitoIdentityProvider::Client]
159- # @raise [RuntimeError]
160- def self . cognito_client
161- @cognito_client ||= Aws ::CognitoIdentityProvider ::Client . new (
162- { region : CognitoRails ::Config . aws_region } . merge ( CognitoRails ::Config . aws_client_credentials )
163- )
164- end
165-
166174 # @return [Array<Hash>]
167175 def general_user_attributes
168176 [
0 commit comments