diff --git a/app/controllers/v1/omniauth_callbacks_controller.rb b/app/controllers/v1/omniauth_callbacks_controller.rb index d5989d5479192d3e6dda62485b73f9941d8c6130..c49c15e792fe96de5fd2084cf2d19a064eba0cd7 100644 --- a/app/controllers/v1/omniauth_callbacks_controller.rb +++ b/app/controllers/v1/omniauth_callbacks_controller.rb @@ -77,13 +77,23 @@ require 'open-uri' # break out provider attribute assignment for easy method extension def assign_provider_attrs(user, auth_hash) - avatar = auth_hash['provider']=='google_oauth2' ? open(auth_hash['info']['image']) : auth_hash['info']['image'] + + email = auth_hash['info']['email'] + avatar = auth_hash['info']['image'] + + # Duplicate emails when logging via facebook and google cause API to crash + # Add +google_oauth2 to google logins to avoid duplication (workaround!!) + # Google ignore strings after '+' until '@gmail.com' (wow!!!) + if auth_hash['provider']=='google_oauth2' + email = auth_hash['info']['email'].split('@')[0] + '+' + auth_hash['provider'] + '@' + auth_hash['info']['email'].split('@')[1] + avatar = open(auth_hash['info']['image']) + end user.assign_attributes({ nickname: auth_hash['info']['nickname'], name: auth_hash['info']['name'], avatar: avatar, - email: auth_hash['info']['email'] + auth_hash['provider'] + email: email }) end