Class: Users::OmniauthCallbacksController

Inherits:
Devise::OmniauthCallbacksController
  • Object
show all
Defined in:
lib/generators/llm_meta_client/authentication/templates/app/controllers/users/omniauth_callbacks_controller.rb

Instance Method Summary collapse

Instance Method Details

#failureObject



23
24
25
# File 'lib/generators/llm_meta_client/authentication/templates/app/controllers/users/omniauth_callbacks_controller.rb', line 23

def failure
  redirect_to root_path, alert: "Failed to authentication. Please try again."
end

#google_oauth2Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/generators/llm_meta_client/authentication/templates/app/controllers/users/omniauth_callbacks_controller.rb', line 2

def google_oauth2
  @user = User.from_omniauth(request.env["omniauth.auth"])

  # Check if the user was successfully saved to the database
  if @user.persisted?
    # Authentication successful: Set flash message and sign in with redirect
    flash[:notice] = I18n.t "devise.omniauth_callbacks.success", kind: "Google"
     @user, event: :authentication
  else
    # Authentication failed: User creation/validation errors occurred
    # This happens when:
    # - Email validation fails
    # - Required fields are missing
    # - Database constraints are violated
    # - User model validations fail

    # Redirect to home with error messages
    redirect_to root_path, alert: @user.errors.full_messages.join("\n")
  end
end