Skip to content

Commit

Permalink
Merge pull request #150 from CodeandoMexico/patch-149
Browse files Browse the repository at this point in the history
omniauth: prevent duplicating accounts
  • Loading branch information
basicavisual authored Nov 6, 2023
2 parents a9cb567 + 94a6d21 commit 2cb42bc
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
Decidim::Devise::OmniauthRegistrationsController.class_eval do
private

def user_params_from_oauth_hash
return nil if oauth_data.empty?

email = oauth_data.dig(:info, :email)
user = Decidim::User.find_by(email: email, organization: current_organization)

{
provider: oauth_data[:provider],
uid: oauth_data[:uid],
name: oauth_data[:info][:name] || user&.name,
nickname: oauth_data[:info][:nickname] || user&.nickname,
oauth_signature: Decidim::OmniauthRegistrationForm.create_signature(oauth_data[:provider], oauth_data[:uid]),
avatar_url: oauth_data[:info][:image],
raw_data: oauth_hash
}
end

def verified_email
@verified_email ||= oauth_data.dig(:info, :email) || params.dig(:user, :email)
end
Expand Down

0 comments on commit 2cb42bc

Please sign in to comment.