class OmniauthSessionsController < ApplicationController skip_before_action :verify_authenticity_token skip_before_action :authenticate def create @<%= singular_table_name %> = <%= class_name %>.where(omniauth_params).first_or_initialize(<%= "#{singular_table_name}_params" %>) if @<%= singular_table_name %>.save session = @<%= singular_table_name %>.sessions.create!(session_params) cookies.signed.permanent[:session_token] = { value: session.id, httponly: true } redirect_to root_path, notice: "Signed in successfully" else redirect_to sign_in_path, alert: "Authentication failed" end end def failure redirect_to sign_in_path, alert: params[:message] end private def omniauth_params { provider: omniauth.provider, uid: omniauth.uid } end def <%= "#{singular_table_name}_params" %> { email: omniauth.info.email, password: SecureRandom::base58, verified: true } end def session_params { user_agent: request.user_agent, ip_address: request.remote_ip, sudo_at: Time.current } end def omniauth request.env["omniauth.auth"] end end