0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

devise_token_authを使ってGETリクエストをすると/omniauth/sessionsへリダイレクトする

Posted at

http://localhost:3000/admin/auth/sessionsへGETリクエストをaxios経由で行うと、意図せずhttp://localhost:3000/omniauth/sessions へリダイレクトしてしまう。
以下がログ。

Started GET "/admin/auth/sessions" for ::1 at 2022-03-04 17:51:33 +0900
Started GET "/omniauth/sessions?namespace_name=admin&resource_class=AdminUser" for ::1 at 2022-03-04 17:51:33 +0900
  
ActionController::RoutingError (No route matches [GET] "/omniauth/sessions"):

こんなときはroute.rbを以下の通り変えてあげると解決する。

config/routes.rb
namespace :admin do
  mount_devise_token_auth_for 'AdminUser',
                              at: 'auth',
++                            skip: [:omniauth_callbacks],
                              controllers: {
                                registrations: 'admin/auth/registrations',
                              }
  namespace :auth do
    resources :sessions, only: %i[index]
  end
end
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?