Devise redirect to facebook isn't working

90 Views Asked by At

Update: Narrowed down the issue to routing table.

devise_for :users, skip: :all

  devise_scope :user do
    get '/auth/:provider/callback' => 'registrations#omniauth'
    get '/auth/facebook/callback' => 'registrations#omniauth'
    get 'vendors/sign_up' => 'registrations#vendor_sign_up'
    post 'vendors/sign_up' => 'registrations#create_vendor_sign_up'
    get 'vendors/thank_you' => 'registrations#vendor_thank_you'
  end

How do I add a get/post route which will map to devise's facebook redirect?

I have followed all the articles on first pages of google search and still unable to get my login with Facebook working. I am getting No route matches [GET] "/auth/facebook" when I click on Login with Facebook button. It is not redirecting me to Facebook at all.

I am using Rails 6, Devise 4.8, Omniauth 2.0.4 and omniauth-facebook 8

My gems:

gem 'omniauth'
gem 'omniauth-facebook'
gem 'devise', github: 'heartcombo/devise'

My omniauth.rb initializer

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :facebook, 'XXXXX', 'XXXXX',scope: 'email', display: 'popup'
end

My routing table has been split into multiple files. But here are the routes for user/signup related methods:

Rails.application.routes.draw do
  devise_for :users, skip: :all 

  devise_scope :user do
    get '/auth/facebook/callback', to: 'callback_handler#facebook'

    get 'vendors/sign_up' => 'registrations#vendor_sign_up'
    post 'vendors/sign_up' => 'registrations#create_vendor_sign_up'
    get 'vendors/thank_you' => 'registrations#vendor_thank_you'
    get 'users/thank_you' => 'registrations#user_thank_you'
  end
end

my link for login is

<%= link_to '/auth/facebook', class:"oatuth-button fb oatuth-btn" do %>
   <i class="fa fa-facebook fa-fw"></i>&nbsp;<%= t(:login_with) %> Facebookk
<% end %>

and here is my CallbackHandler

class CallbackHandlerController < Devise::OmniauthCallbacksController

  skip_before_action :authenticate_user!, raise: false
  def all
    p request.env["omniauth.auth"]
    user = User.from_omniauth(request.env["omniauth.auth"], current_user)
    if user.save
      session[:user_id] = user.id
      sign_in(user)
      redirect_to home_path
    else
      render :new
    end
 end



def failure
    #handle you logic here..
    #and delegate to super.
    super
  end


  alias_method :facebook, :all
  # alias_method :twitter, :all
  # alias_method :linkedin, :all
  # alias_method :github, :all
  # alias_method :passthru, :all
  alias_method :google_oauth2, :all
end

when I click on this button, i am getting No Route matches GET /auth/facebook

Any ideas what am I missing here?

Thanks

0

There are 0 best solutions below