You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -432,7 +434,13 @@ restricted to authenticated users and you can only do this at the root level fie
432
434
schema. Configure the plugin as explained [here](#mounting-operations-into-your-own-schema)
433
435
so this can work.
434
436
435
-
In you main app's schema this is how you might specify if a field needs to be authenticated or not:
437
+
##### Authentication Options
438
+
Wether you setup authentications as a default in the plugin, or you do it at the field level,
439
+
these are the options you can use:
440
+
1.**Any truthy value:** If `current_resource` is not `.present?`, query will return an authentication error.
441
+
1.**A callable object:** Provided object will be called with `current_resource` as the only argument if `current_resource` is `.present?`. If return value of the callable object is false, query will return an authentication error.
442
+
443
+
In your main app's schema this is how you might specify if a field needs to be authenticated or not:
436
444
```ruby
437
445
moduleTypes
438
446
classQueryType < Types::BaseObject
@@ -442,13 +450,11 @@ module Types
442
450
field :public_field, String, null:false, authenticate:false
443
451
# this field requires authentication
444
452
field :private_field, String, null:false, authenticate:true
453
+
# this field requires authenticated users to also be admins
454
+
field :admin_field, String, null:false, authenticate:->(user) { user.admin? }
445
455
end
446
456
end
447
457
```
448
-
**Important:** Currently, the only check the plugin does to see if the user is authenticated or not when executing
449
-
the query, is verifying that `context[:current_resource].present?` in the GraphQL context.
450
-
So, be careful not to populate that key of the context with values other than what `gql_devise_context`
451
-
returns. The option to do more complex verifications will be added in the future.
452
458
453
459
#### Authenticate Before Reaching Your GQL Schema (Deprecated)
454
460
For this you will need to call `authenticate_<model>!` in a `before_action` controller hook.
@@ -506,7 +512,13 @@ restricted to authenticated users and you can only do this at the root level fie
506
512
schema. Configure the plugin as explained [here](#mounting-operations-into-your-own-schema)
507
513
so this can work.
508
514
509
-
In you main app's schema this is how you might specify if a field needs to be authenticated or not:
515
+
##### Authentication Options
516
+
Wether you setup authentications as a default in the plugin, or you do it at the field level,
517
+
these are the options you can use:
518
+
1.**Any truthy value:** If `current_resource` is not `.present?`, query will return an authentication error.
519
+
1.**A callable object:** Provided object will be called with `current_resource` as the only argument if `current_resource` is `.present?`. If return value of the callable object is false, query will return an authentication error.
520
+
521
+
In your main app's schema this is how you might specify if a field needs to be authenticated or not:
510
522
```ruby
511
523
moduleTypes
512
524
classQueryType < Types::BaseObject
@@ -516,6 +528,8 @@ module Types
516
528
field :public_field, String, null:false, authenticate:false
517
529
# this field requires authentication
518
530
field :private_field, String, null:false, authenticate:true
531
+
# this field requires authenticated users to also be admins
532
+
field :admin_field, String, null:false, authenticate:->(user) { user.admin? }
0 commit comments