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 when not using Devise #10

Open
sapientpants opened this issue May 7, 2018 · 3 comments
Open

current_user when not using Devise #10

sapientpants opened this issue May 7, 2018 · 3 comments

Comments

@sapientpants
Copy link
Contributor

Any thoughts as to how current_user should be made available when Devise (and hence its helper that generates current_user) isn't being used?

I'm happy to work on this, but wanted to ask if anyone has an idea for how this should be done.

@michelson
Copy link
Contributor

michelson commented May 7, 2018 via email

@sapientpants
Copy link
Contributor Author

Off the top of my head I can think of two approaches.

  1. Refactor my application to move current_user from my ApplicationController into a concern that can be then included in my ApplicationController and injected into the GDPR one similar to the Devise approach.
  2. Passing a lambda in via the Config object.

I include option 2 for completeness as it seems even less elegant than option 1 which itself is not particularly nice.

It'd be nice if GDPR could just use current_user from my ApplicationController without me having to do anything extra.

@viamin
Copy link
Contributor

viamin commented May 24, 2018

This is also a problem for Devise users that use a model other than User for authentication. If you're authenticating a Person, for example, Devise creates current_person instead of current_user.

I've worked around this by creating a controller concern (app/controllers/concerns/auth_helpers.rb):

module AuthHelpers
  extend ActiveSupport::Concern

  def current_user
    current_person # assumes the Devise helpers are also included
  end
end

and I include this in the PolicyManager ApplicationController (in config/initializers/gdpr.rb):

PolicyManager::ApplicationController.send(:include, AuthHelpers)

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

3 participants