Skip to content

Commit 796220f

Browse files
committed
Fixes #192 - Update context upon login
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 - #192
1 parent a69b27a commit 796220f

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

lib/graphql_devise/mutations/login.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ def resolve(email:, password:)
2424

2525
yield resource if block_given?
2626

27+
context[:current_resource] = resource if context[:current_resource].nil?
28+
2729
{ authenticatable: resource, credentials: new_headers }
2830
elsif resource && !active_for_authentication?(resource)
2931
if locked?(resource)

0 commit comments

Comments
 (0)