Here is my session controller omniauth method
def omniauth
user=User.find_or_create_by(uid: request.env['omniauth.auth'][:uid], provider:
request.env['omniauth.auth'][:provider]) do |u|
u.email=request.env['omniauth.auth'][:info][:email]
u.password=SecureRandom.hex(15)
end
if user.valid?
session[:user_id]=user.id
redirect_to root_path
else
redirect_to sign_in_path
end
end
Here is my config/initializer/omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
provider :google_oauth2, ENV['GOOGLE_CLIENT_ID'], ENV['GOOGLE_CLIENT_SECRET']
end
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, ENV['FACEBOOK_APP_ID'], ENV['FACEBOOK_APP_SECRET'],
client_options: {
site: 'https://graph.facebook.com/v7.0',
authorize_url: "https://www.facebook.com/v7.0/dialog/oauth"
}
end
OmniAuth.config.allowed_request_methods = %i[get]
Here is my link_to tag for FB login
<%= link_to 'Log in with fb', '/auth/facebbok/callback', method: :post %>
Here is my route for omniauth
get '/auth/:provider/callback', to: 'sessions#omniauth'
And the problem that I was dancing is this error enter image description here