ignore when FranceConnect calls callback 2 times
This commit is contained in:
parent
a288a13805
commit
966ee33529
1 changed files with 12 additions and 5 deletions
|
@ -23,11 +23,18 @@ class FranceConnectInformation < ApplicationRecord
|
|||
user = User.find_by(email: email_france_connect.downcase)
|
||||
|
||||
if user.nil?
|
||||
user = User.create!(
|
||||
email: email_france_connect.downcase,
|
||||
password: Devise.friendly_token[0, 20],
|
||||
confirmed_at: Time.zone.now
|
||||
)
|
||||
begin
|
||||
user = User.create!(
|
||||
email: email_france_connect.downcase,
|
||||
password: Devise.friendly_token[0, 20],
|
||||
confirmed_at: Time.zone.now
|
||||
)
|
||||
rescue ActiveRecord::RecordNotUnique
|
||||
# ignore this exception because we check before is user is nil.
|
||||
# exception can be raised in race conditions, when FranceConnect calls callback 2 times.
|
||||
# At the 2nd call, user is nil but exception is raised at the creation of the user
|
||||
# because the first call has already created a user
|
||||
end
|
||||
end
|
||||
|
||||
update_attribute('user_id', user.id)
|
||||
|
|
Loading…
Reference in a new issue