Skip to content

Commit

Permalink
omniauth: prevent duplicating accounts
Browse files Browse the repository at this point in the history
Closes: #149
  • Loading branch information
samanera committed Nov 4, 2023
1 parent a9cb567 commit 94a6d21
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 94a6d21

Please sign in to comment.