sync_attr_with_auth0 0.0.22 → 0.0.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c7788c4f5abc0773865898d924dc408dcec79679
4
- data.tar.gz: f72a93fd6f27bc23a93cf35ceacbf454ed1a3948
3
+ metadata.gz: a2bf2d9667067ee4ddf2b3a0f6984d4f6dbd1718
4
+ data.tar.gz: 2987a1a6425a37450e8f23f853ab651c9fa1d289
5
5
  SHA512:
6
- metadata.gz: 6bfad2038da2670a9d7f1f20868d397198bd1291f3413bc889adb2b082c661a8d2fffbb647c4ab8a7cc6db322e24b6673576b04896afb647cdd6642beaa4286f
7
- data.tar.gz: 6a139dfb402e6e7227b19d8afb2aad3098100ebc7a1193ea01df6e52fa44fb48a161a2e5acbc25e831a55cedf6e54b596bf2476c750f537cf9893cc385af43c8
6
+ metadata.gz: acbe5201cad579b763012e6e72f1916f9465ff7c31d82857887e01ac57778685bd553f8239bc6d325bac879c9a20458c73df05295c072300ab915bdc8c7a49c3
7
+ data.tar.gz: 502b60f1108226edb88c752139b8ecda5816e28109b563d616d33444b7b9c840f99fb28cfc10a43c7ceab2ab5775c044430cb358082af3f022bb8c533c503dd3
@@ -15,6 +15,7 @@ module SyncAttrWithAuth0
15
15
  after_validation :validate_email_with_auth0
16
16
  after_create :auth0_create
17
17
  after_update :auth0_update, if: :auth0_dirty?
18
+ after_commit :auth0_set_uid
18
19
  end
19
20
 
20
21
  private
@@ -106,6 +107,21 @@ module SyncAttrWithAuth0
106
107
  true # don't abort the callback chain
107
108
  end
108
109
 
110
+ def auth0_set_uid
111
+ if @auth0_uid
112
+ self.sync_with_auth0_on_update = false if self.respond_to?(:sync_with_auth0_on_update=)
113
+ self.send("#{auth0_sync_options[:uid_att]}=", @auth0_uid)
114
+
115
+ # Nil the instance variable to prevent an infinite loop
116
+ @auth0_uid = nil
117
+
118
+ # Save!
119
+ self.save
120
+ end
121
+
122
+ true # don't abort the callback chain
123
+ end
124
+
109
125
  def create_user_in_auth0()
110
126
  user_metadata = auth0_user_metadata
111
127
 
@@ -128,9 +144,8 @@ module SyncAttrWithAuth0
128
144
 
129
145
  response = auth0.create_user(self.send(auth0_sync_options[:name_att]), args)
130
146
 
131
- # Update the record with the uid
132
- self.send("#{auth0_sync_options[:uid_att]}=", response['user_id'])
133
- self.save
147
+ # Update the record with the uid after_commit
148
+ @auth0_uid = response['user_id']
134
149
  end
135
150
 
136
151
  def update_user_in_auth0(uid)
@@ -173,8 +188,8 @@ module SyncAttrWithAuth0
173
188
  auth0 = SyncAttrWithAuth0::Auth0.create_auth0_client
174
189
  auth0.patch_user(found_user['user_id'], args)
175
190
 
176
- self.send("#{auth0_sync_options[:uid_att]}=", found_user['user_id'])
177
- self.save
191
+ # Update the record with the uid after_commit
192
+ @auth0_uid = found_user['user_id']
178
193
  end
179
194
 
180
195
  rescue Exception => e
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sync_attr_with_auth0
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.22
4
+ version: 0.0.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick McGraw