Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

User is getting passed to the policy as nil. #58

Open
jejacks0n opened this issue Jul 27, 2018 · 2 comments
Open

User is getting passed to the policy as nil. #58

jejacks0n opened this issue Jul 27, 2018 · 2 comments

Comments

@jejacks0n
Copy link

This is true in released gem and master, the reason seems to be around this line:

https://github.com/ontohub/graphql-pundit/blob/master/lib/graphql-pundit/authorization.rb#L58

We don't see self.class.current_user being set to anything by default, and so I'm guessing the tests might set it but it isn't being defaulted in actual code.

I've worked around this by reopening the class and defining a current_user class method e.g. monkeypatching. note that I'm using rails and so can chain the namespace.

class GraphQL::Pundit::Field
  def self.current_user
    :current_user
  end
end
@jejacks0n jejacks0n changed the title User is getting passed to the policy initialize as nil. User is getting passed to the policy as nil. Jul 27, 2018
@aponsin
Copy link

aponsin commented Aug 13, 2018

Same issue for me. The fix does the trick.

@elliotcm
Copy link

Well this issue just burned an hour of my life. Thank you for the workaround.

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

No branches or pull requests

3 participants