# frozen_string_literal: true class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController def github handle_auth('GitHub') end def google_oauth2 handle_auth('Google') end private def handle_auth(provider) @user = User.from_omniauth(request.env['omniauth.auth']) if @user.persisted? flash[:notice] = I18n.t 'devise.omniauth_callbacks.success', kind: provider sign_in_and_redirect @user, event: :authentication else redirect_to new_user_registration_url, alert: @user.errors.full_messages.join("\n") end end def failure redirect_to root_path, alert: "Authentication failed: #{params[:message]}" end end