Damir Nurgaliev
Damir Nurgaliev

Reputation: 351

Logout routing using OAuth and Rails

I'm using OAuth 2 gem to authenticate via google and facebook. I need to do logout from google and facebook when I logout from my application. In OA documentation said to:

devise_scope :user do
delete 'sign_out', to: 'devise/sessions#destroy', as: :destroy_user_session
end

Add this to routes.rb. I did it so, my routs rb now looks like:

Rails.application.routes.draw do
  devise_for :users, controllers: { omniauth_callbacks: 'callbacks' }
  devise_scope :user do
    delete 'sign_out', to: 'devise/sessions#destroy', as: :destroy_user_session
  end

When I add this line, i got an error when i try to rails s my application:

/Users/damirik/.rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/routing/route_set.rb:507:in add_route': Invalid route name, already in use: 'destroy_user_session' (ArgumentError) You may have defined two routes with the same name using the:as` option, or you may be overriding a route already defined by a resource with the same naming.

I really dont understand how to fix it. Help please

Upvotes: 1

Views: 517

Answers (1)

Sebastian
Sebastian

Reputation: 2204

Looking at the devise_for method documentation, I can see that it already adds the exact delete 'sign_out' route, which makes it redundant.

This should be enough to make your code work.

Rails.application.routes.draw do
  devise_for :users, controllers: { omniauth_callbacks: 'callbacks' }
end

Upvotes: 3

Related Questions