Skip to content

Set context[:current_resource] upon login#193

Merged
mcelicalderon merged 1 commit intographql-devise:masterfrom
TomasBarry:feature/update-context-upon-login
Aug 2, 2021
Merged

Set context[:current_resource] upon login#193
mcelicalderon merged 1 commit intographql-devise:masterfrom
TomasBarry:feature/update-context-upon-login

Conversation

@TomasBarry
Copy link
Copy Markdown
Contributor

If using Object Authorization
that relies on context[:current_resource] it is not possible to query
for data on the authenticatable object since context[:current_user] is
nil after logging in since this is set at the controller level.

This commit fixes this by setting context[:current_resource] to
resource if context[:current_resource] is nil (as the
implementation may override this already).

GitHub issue - #192

If using [Object Authorization](https://graphql-ruby.org/authorization/authorization.html#object-authorization)
that relies on `context[:current_resource]` it is not possible to query
for data on the authenticatable object since `context[:current_user]` is
`nil` after logging in since this is set at the controller level.

This commit fixes this by setting `context[:current_resource]` to
`resource` _if_ `context[:current_resource]` is `nil` (as the
implementation may override this already).

GitHub issue - graphql-devise#192
@TomasBarry
Copy link
Copy Markdown
Contributor Author

TomasBarry commented Aug 2, 2021

@mcelicalderon, how would you like this to be tested, or is this sufficient?

Edit: test failures are confusing me a bit. Any idea what it may be?

@mcelicalderon
Copy link
Copy Markdown
Member

mcelicalderon commented Aug 2, 2021

Thank you, @TomasBarry! I can think of a way of testing that right now, but we can take care of that afterwards as existing tests didn't break. Apparently dta finally stopped supporting ruby 2.2 and that's why one of tests failed. As that's one of our main dependencies, we will drop support too. I'll fix that before merging your PR, so máster doesn't fail.

@mcelicalderon mcelicalderon merged commit a324b69 into graphql-devise:master Aug 2, 2021
@mcelicalderon mcelicalderon added the enhancement New feature or request label Aug 2, 2021
@mcelicalderon mcelicalderon changed the title Fixes #192 - Update context upon login Set context[:current_resource] upon login Aug 2, 2021
@TomasBarry TomasBarry deleted the feature/update-context-upon-login branch August 3, 2021 08:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants