add oauth with google

This commit is contained in:
João Geonizeli
2022-07-20 22:22:41 -03:00
parent 072e1de01b
commit ae7d31bc1b
9 changed files with 74 additions and 6 deletions

View File

@@ -0,0 +1,16 @@
module Users
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
def google_oauth2
# You need to implement the method below in your model (e.g. app/models/user.rb)
@user = User.find_by!(email: request.env['omniauth.auth'].info['email'])
flash[:notice] = I18n.t 'devise.omniauth_callbacks.success', kind: 'Google'
sign_in_and_redirect @user, event: :authentication
rescue ActiveRecord::RecordNotFound => e
# Removing extra as it can overflow some session stores
session['devise.google_data'] = request.env['omniauth.auth'].except('extra')
redirect_to new_user_registration_url, alert: e.message
end
end
end