I have 2 ways of loggin in to my app. the first way is to loggin via email the next one is loggin via social media.
I have installed devise and omniauth, omniauth-facebook,twitter and google plus. I have successfully implemented the normal login in via devise but when I try to login via fb or twitter or gplus by visiting /auth/facebook it says route not found.
Rails.application.routes.draw do
devise_for :users
root to: 'visitors#index'
get '/auth/:provider/callback' => 'sessions#create'
get '/signin' => 'sessions#new', as: :signin
get '/signout' => 'sessions#destroy', as: :signout
get '/auth/failure' => 'sessions#failure'
end
//session_controller.rb
class SessionsController < ApplicationController
def new
redirect_to '/auth/facebook'
end
def create
auth = request.env['omniauth.auth']
user = User.where(provider: auth['provider'],
uid: auth['uid'].to_s).first || User.create_with_omniauth(auth)
reset_session
session[:user_id] = user.id
redirect_to root_url, notice: 'Signed in!'
end
def destroy
reset_session
redirect_to root_url, notice: 'Signed out!'
end
def failure
redirect_to root_url, alert: "Authentication error: #{params[:message].humanize}"
end
end
//omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, ENV['FACEBOOK_KEY'], ENV['FACEBOOK_SECRET'],
scope: 'public_profile', info_fields: 'id,name,link'
provider :twitter, ENV['TWITTER_KEY'], ENV['TWITTER_SECRET']
provider :google_oauth2, ENV['GOOGLE_CLIENT_ID'], ENV['GOOGLE_SECRET'],
scope: 'profile', image_aspect_ratio: 'square', image_size: 48,
access_type: 'online', name: 'google'
end