You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I created the auth providers for Google/FB as shown in the Wiki, however, there is a use case where a user has already signed up with a normal account in the past and then tries to log in with Facebook/Google where the email already exists. This would throw an ActiveRecord::RecordInvalid exception upon account creation, how am I supposed to get that into the response to let the user know that an account with that email already exists ?
Here is the code:
doorkeeper.rb
resource_owner_from_assertion do
provider = params[:provider]
case provider
when "google"
g = ExternalAuth::Google.new(params[:assertion])
g.get_user!
when "facebook"
f = ExternalAuth::Facebook.new(params[:assertion])
begin
f.get_user!
rescue ActiveRecord::RecordInvalid => e
#what happens here ?
end
end
end
end
facebook_auth.rb
def get_user!
if user_data.present?
user = User.where(fb_id: user_data["id"]).first
if user.blank?
user = User.new(
remote_profile_image_url: image["data"]["url"],
fb_id: user_data["id"],
firstname: user_data["first_name"],
lastname: user_data["last_name"],
email: user_data["email"]
)
user.password = SecureRandom.hex
user.save!
end
user
else
nil
end
end
The text was updated successfully, but these errors were encountered:
I guess the easiest would be to raise an instance of DoorkeeperError (aka StandardError), eg: raise Doorkeeper::Errors::DoorkeeperError.new('email already exists')
First of all, thank you for creating this gem!
I created the auth providers for Google/FB as shown in the Wiki, however, there is a use case where a user has already signed up with a normal account in the past and then tries to log in with Facebook/Google where the email already exists. This would throw an ActiveRecord::RecordInvalid exception upon account creation, how am I supposed to get that into the response to let the user know that an account with that email already exists ?
Here is the code:
doorkeeper.rb
facebook_auth.rb
The text was updated successfully, but these errors were encountered: