Skip to content
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

Current user argunment #32

Open
olvap opened this issue Jan 30, 2020 · 3 comments
Open

Current user argunment #32

olvap opened this issue Jan 30, 2020 · 3 comments

Comments

@olvap
Copy link

olvap commented Jan 30, 2020

Hello,
I see in the documentation for custom strategies that can only check features if we have the user's session. The problem with that is that the current user is not always obtain the same way in different parts of a application (API token, sso, session) and I would like to have an option to pass the current_user object directly like:

def enabled?(feature, current_user)
  current_user.enabled_features[feature]
end

How could do it do something like this possible?

@rolftimmermans
Copy link
Member

I imagine you have a request object in all cases? So the solution would be to unify whatever differences you have by inspecting the request and retrieve the user information in different ways depending on the request parameters/hostname/session/path, etc.

@olvap
Copy link
Author

olvap commented Jan 30, 2020

hey @rolftimmermans, thanks for your response,

so you mean something like this?

def enabled?(feature)
  current_user.enabled_features[feature]
end

def current_user
  if(request_has_session?)
    request.get_current_user_by_session_id
  elsif(request_has_a_token)
    request.get_current_user_by_token
  end
end

@rolftimmermans
Copy link
Member

Yes, pretty much that. Does that help?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants