dawarich/app/controllers/users/omniauth_callbacks_controller.rb
2025-10-26 15:27:43 +01:00

19 lines
648 B
Ruby

# frozen_string_literal: true
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def github
@user = User.from_omniauth(request.env['omniauth.auth'])
if @user.persisted?
flash[:notice] = I18n.t 'devise.omniauth_callbacks.success', kind: 'GitHub'
sign_in_and_redirect @user, event: :authentication
else
session['devise.github_data'] = request.env['omniauth.auth'].except('extra')
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