-
Notifications
You must be signed in to change notification settings - Fork 20
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
Using Authie in route middleware #20
Comments
Small update; Whenever I tried to implement the current logic from the class UserKindConstraint
class RackController
def initialize(request)
@env = request.env
@request = request
end
def auth_session
@auth_session ||= Authie::Session.get_session(self)
end
def current_user
auth_session.user if auth_session.is_a?(Authie::Session)
end
end
def initialize(user_type)
@user_type = user_type
end
# Only returns true if there is a session with a user_id in it, if the user
# can be found, and that user has the proper kind. False in every other case.
def matches?(request)
controller = RackController.new(request)
current_user = controller.current_user
current_user && current_user.send("#{@user_type}?".to_sym)
end
end |
This is two years later, so I don't know if you're still having this problem (or even still using Authie), but I found that adding this: require 'authie/rack_controller' at the top of my constraint file did the trick. It doesn't look like the gem loads that class by default. |
I'm not using it anymore indeed, but thanks for providing the answer to my question @skylarmacdonald! At least it will help the community to find the answer :)! |
Hi there,
I've got a question regarding to using the current_user in a route constraint of Rails. I've got a route constraint in which I check the role of the authenticated user (if any) and adjust the root_path according to their role.
The code looks something like this;
But it seems the
Authie::RackController
can't be loaded. Any ideas why this happens, whether it's intended or am I just doing something wrong?Cheers
The text was updated successfully, but these errors were encountered: