-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Authenticated Route Constraints #1147
Conversation
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 |
@josevalim: because 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! |
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.) |
Warden::Proxy#authenticated? and Warden::Proxy#unauthenticated? don't try strategies first.
Fully tested. Caught a problem the last commit, too. -.- |
Authenticated Route Constraints
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: authenticated do
root :to => :dashboard
end
# unauthenticated:
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
My proposed syntax for it would be:
(Unless there is already a way of doing the same from the controller that I am not aware of.) |
@sj26, @josevalim: Thank you! |
Allows routing based on authentication state, optionally by scope.
The example included in the comments for #authenticated: