Allows routing based on authentication state, optionally by scope.
The example included in the comments for #authenticated:
authenticated :admin do
root :to => 'admin/dashboard#show'
root :to => 'dashboard#show'
root :to => 'landing#show'
Add #authenticated and #not_authenticated route constraints
Thanks for the pull request, but why would I use authenticated instead of authenticated?
@josevalim what's the question again? :)
Hahaha, LOL, sorry.
The question is: why would I use authenticated instead of the existing authenticate?
@josevalim: because authenticate forces authentication, authenticated only checks for it.
With authenticated I can provide the same path twice but route differently based on authentication state. A classic example is github itself. Unauthenticated users see a landing page extorting github's virtue, authenticated users see a dashboard of recent activity and repositories, both at the root URL.
Oh, that's great. I like it. Could you please provide tests then?
Awesome, yeah, I wanted to get feedback before doing so. I'll chuck some together now, cheers!
Oh hey, Warden has API for this. Should probably match the name, too.
Hey mate, any news? I am planning to release Devise 1.4 in the next 24 hours. So if you can add tests, we can get it in!
Oh man, okay, I'll get cracking.
(Opposite timezone fail.)
Switch to Warden::Proxy#authenticate?
Warden::Proxy#authenticated? and Warden::Proxy#unauthenticated? don't try strategies first.
Fully tested. Caught a problem the last commit, too. -.-
This is a great addition to devise. Thanks sj26 for contributing and josevalim for merging!
This feature would be even better if we could specify some pages that be shown only to unauthenticated users. Like the registration and login pages, for instance. Then anyone requesting those pages can be redirected to the landing page for that model.
unauthenticated was added to Devise later with exactly this behavior.
... or you could just have later routes which, implicitly, are unauthenticated:
root :to => :dashboard
root :to => :home
Oh, nevermind, I get you might want to have routes only accessible to unauthenticated users unmasked by authenticated routes.
Also, useful for skipping a whole section of unauthenticated routes as an efficiency gain.
Isn't unauthenticated the same as the default root path? What I had in mind was more like a way of making sure authenticated users never get to see "new registration" and "new session" pages. It would be a way of doing the same thing as what this line from my registrations_controller.rb is doing right now:
redirect_to stored_location_for(current_user) if signed_in?
My proposed syntax for it would be:
authenticated, :force =>[:registrations,:sessions] do
as :user do
root :to => "pages#index"
(Unless there is already a way of doing the same from the controller that I am not aware of.)
@sj26, @josevalim: Thank you!