Devise authentication for sinatra app mounted in R

2019-05-08 01:06发布

问题:

I am using -

  • Rails 3.2.2
  • Ruby 1.9.3
  • Devise 2.0.4

my route file looks like this:

Foo::Application.routes.draw do
  devise_for :admins

  root :to => "home#index"
  authenticate :admin do
    mount Simple::App, at: '/simple'
  end 
end

access under /simple needs to be authenticated.

However if not signed in , access to /simple/* will be redirect to /simple/admin/sign_in instead of just /admin/sign_in which creates a redirect loop.

Do I need to create a custom failure_app to correct this behavior?

Thanks!

回答1:

 Foo::Application.routes.draw do
   devise_for(:admins)

   root(to: 'home#index')

   match('/simple/admins/sign_in' => redirect('/admins/sign_in'))
   authenticate(:admin) do
     mount(Simple::App, at: 'simple')
   end 
 end