Skip to content
This repository has been archived by the owner on Mar 22, 2021. It is now read-only.

Setting @current_user in authenticable.rb #1

Closed
hzalaz opened this issue Jul 16, 2015 · 2 comments
Closed

Setting @current_user in authenticable.rb #1

hzalaz opened this issue Jul 16, 2015 · 2 comments
Assignees

Comments

@hzalaz
Copy link

hzalaz commented Jul 16, 2015

In authenticable.rb the @current_user is retrieved like this

@current_user = User.find(payload['user_id'])

but since there is no User model in the lib it will force whoever who uses knock to have a model named User and expect a claim named user_id to be present in the JWT.
What I'd like to have is a way to define how the user is retrieved from my DB, e.g. in my app's config/knock.rb I could have:

config.current_user_from_token = -> (claims) { User.find(claims['sub']) }

and then in authenticable.rb

@current_user = Knock.current_user_from_token.call(payload)

This will allow to fetch the user from any model using any claim in the JWT

@nsarno nsarno self-assigned this Jul 16, 2015
@nsarno
Copy link
Owner

nsarno commented Jul 16, 2015

The gem in its original version is very opinionated as it's pulled from personal use cases. But I totally agree that it should evolve towards a more generic solution.

Thank you for your suggestions, I implemented them. This should resolve the issue.

@nsarno
Copy link
Owner

nsarno commented Jul 16, 2015

I released a new version of the gem (1.2.0)

@nsarno nsarno closed this as completed Jul 16, 2015
muZk added a commit to muZk/knock that referenced this issue Jul 10, 2020
muZk added a commit to muZk/knock that referenced this issue Jul 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants