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
@@ -297,17 +291,11 @@ The following is a list of the symbols you can provide to the `operations`, `ski
297
291
```ruby
298
292
:login
299
293
:logout
300
-
:sign_up (deprecated)
301
294
:register
302
-
:update_password (deprecated)
303
295
:update_password_with_token
304
-
:send_password_reset (deprecated)
305
296
:send_password_reset_with_token
306
-
:resend_confirmation (deprecated)
307
297
:resend_confirmation_with_token
308
298
:confirm_registration_with_token
309
-
:confirm_account (deprecated)
310
-
:check_password_token (deprecated)
311
299
```
312
300
313
301
### Configuring Model
@@ -369,31 +357,6 @@ user.update_with_email(
369
357
)
370
358
```
371
359
372
-
#### Deprecated flow - Do Not Use
373
-
`update_with_email` requires two additional attributes when email will change or an error
374
-
will be raised:
375
-
376
-
-`schema_url`: The full url where your GQL schema is mounted. You can get this value from the
377
-
controller available in the context of your mutations and queries like this:
378
-
```ruby
379
-
context[:controller].full_url_without_params
380
-
```
381
-
-`confirmation_success_url`: This the full url where you want users to be redirected after
382
-
the email has changed successfully (usually a front-end url). This value is mandatory
383
-
unless you have set `default_confirm_success_url` in your devise_token_auth initializer.
384
-
385
-
So, it's up to you where you require confirmation of changing emails.
386
-
[Here's an example](https://github.com/graphql-devise/graphql_devise/blob/c4dcb17e98f8d84cc5ac002c66ed98a797d3bc82/spec/dummy/app/graphql/mutations/update_user.rb#L13)
387
-
on how you might do this. And also a demonstration on the method usage:
388
-
```ruby
389
-
user.update_with_email(
390
-
name:'New Name',
391
-
email:'new@domain.com',
392
-
schema_url:'http://localhost:3000/graphql',
393
-
confirmation_success_url:'https://google.com'
394
-
)
395
-
```
396
-
397
360
### Customizing Email Templates
398
361
The approach of this gem is a bit different from DeviseTokenAuth. We have placed our templates in `app/views/graphql_devise/mailer`,
399
362
so if you want to change them, place yours on the same dir structure on your Rails project. You can customize these two templates:
@@ -479,87 +442,6 @@ module Types
479
442
end
480
443
```
481
444
482
-
#### Authenticate Before Reaching Your GQL Schema (Deprecated)
483
-
For this you will need to call `authenticate_<model>!` in a `before_action` controller hook.
484
-
In our example our model is `User`, so it would look like this:
485
-
```ruby
486
-
# app/controllers/my_controller.rb
487
-
488
-
classMyController < ApplicationController
489
-
includeGraphqlDevise::Concerns::SetUserByToken
490
-
491
-
before_action :authenticate_user!
492
-
493
-
defmy_action
494
-
result =DummySchema.execute(params[:query], context: { current_resource: current_user })
495
-
render json: result unless performed?
496
-
end
497
-
end
498
-
```
499
-
500
-
The install generator can include the concern in you application controller.
501
-
If authentication fails for a request, execution will halt and a REST error will be returned since the request never reaches your GQL schema.
502
-
503
-
#### Authenticate in an Existing Schema (Deprecated)
504
-
For this you will need to add the `GraphqlDevise::SchemaPlugin` to your schema as described
result =DummySchema.execute(params[:query], context: graphql_context(:user))
515
-
render json: result unless performed?
516
-
end
517
-
end
518
-
```
519
-
The `graphql_context` method receives a symbol identifying the resource you are trying
520
-
to authenticate. So if you mounted the `User` resource, the symbol is `:user`. You can use
521
-
this snippet to find the symbol for more complex scenarios
522
-
`resource_klass.to_s.underscore.tr('/', '_').to_sym`. `graphql_context` can also take an
523
-
array of resources if you mounted more than one into your schema. The gem will try to
524
-
authenticate a resource for each element on the array until it finds one.
525
-
526
-
Internally in your own mutations and queries a key `current_resource` will be available in
527
-
the context if a resource was successfully authenticated or `nil` otherwise.
528
-
529
-
Keep in mind that sending multiple values to the `graphql_context` method means that depending
530
-
on who makes the request, the context value `current_resource` might contain instances of the
531
-
different models you might have mounted into the schema.
532
-
533
-
Please note that by using this mechanism your GQL schema will be in control of what queries are
534
-
restricted to authenticated users and you can only do this at the root level fields of your GQL
535
-
schema. Configure the plugin as explained [here](#mounting-operations-into-your-own-schema)
536
-
so this can work.
537
-
538
-
##### Authentication Options
539
-
Whether you setup authentications as a default in the plugin, or you do it at the field level,
540
-
these are the options you can use:
541
-
1.**Any truthy value:** If `current_resource` is not `.present?`, query will return an authentication error.
542
-
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.
543
-
544
-
In your main app's schema this is how you might specify if a field needs to be authenticated or not:
545
-
```ruby
546
-
moduleTypes
547
-
classQueryType < Types::BaseObject
548
-
# user field used the default set in the Plugin's initializer
549
-
field :user, resolver:Resolvers::UserShow
550
-
# this field will never require authentication
551
-
field :public_field, String, null:false, authenticate:false
552
-
# this field requires authentication
553
-
field :private_field, String, null:false, authenticate:true
554
-
# this field requires authenticated users to also be admins
555
-
field :admin_field, String, null:false, authenticate:->(user) { user.admin? }
556
-
end
557
-
end
558
-
```
559
-
560
-
#### Important
561
-
Remember to check `performed?` before rendering the result of the graphql operation. This is required because some operations perform a redirect and without this check you will get a `AbstractController::DoubleRenderError`.
562
-
563
445
### Making Requests
564
446
Here is a list of the available mutations and queries assuming your mounted model is `User`.
565
447
@@ -572,30 +454,10 @@ Operation | Description | Example
572
454
:--- | :--- | :------------------:
573
455
login | This mutation has a second field by default. `credentials` can be fetched directly on the mutation return type.<br>Credentials are still returned in the headers of the response. | userLogin(email: String!, password: String!): UserLoginPayload |
574
456
logout | requires authentication headers. Deletes current session if successful. | userLogout: UserLogoutPayload |
575
-
signUp **(Deprecated)** | The parameter `confirmSuccessUrl` is optional unless you are using the `confirmable` plugin from Devise in your `resource`'s model. If you have `confirmable` set up, you will have to provide it unless you have `config.default_confirm_success_url` set in `config/initializers/devise_token_auth.rb`. | userSignUp(email: String!, password: String!, passwordConfirmation: String!, confirmSuccessUrl: String): UserSignUpPayload |
576
457
register | The parameter `confirmUrl` is optional unless you are using the `confirmable` plugin from Devise in your `resource`'s model. If you have `confirmable` set up, you will have to provide it unless you have `config.default_confirm_success_url` set in `config/initializers/devise_token_auth.rb`. | userRegister(email: String!, password: String!, passwordConfirmation: String!, confirmUrl: String): UserRegisterPayload |
577
458
sendPasswordResetWithToken | Sends an email to the provided address with a link to reset the password of the resource. First step of the most recently implemented password reset flow. | userSendPasswordResetWithToken(email: String!, redirectUrl: String!): UserSendPasswordResetWithTokenPayload |
578
459
updatePasswordWithToken | Uses a `resetPasswordToken` to update the password of a resource. Second and last step of the most recently implemented password reset flow. | userSendPasswordResetWithToken(resetPasswordToken: String!, password: String!, passwordConfirmation: String!): UserUpdatePasswordWithTokenPayload |
579
-
resendConfirmation **(Deprecated)** | The `UserResendConfirmationPayload` will return a `message: String!` that can be used to notify a user what to do after the instructions were sent to them | userResendConfirmation(email: String!, redirectUrl: String!): UserResendConfirmationPayload |
580
460
resendConfirmationWithToken | The `UserResendConfirmationWithTokenPayload` will return a `message: String!` that can be used to notify a user what to do after the instructions were sent to them. Email will contain a link to the provided `confirmUrl` and a `confirmationToken` query param. | userResendConfirmationWithToken(email: String!, confirmUrl: String!): UserResendConfirmationWithTokenPayload |
581
-
sendResetPassword **(Deprecated)** | Sends an email to the provided address with a link to reset the password of the resource. **This mutation is part of the first and soon to be deprecated password reset flow.** | userSendResetPassword(email: String!, redirectUrl: String!): UserSendResetPasswordPayload |
582
-
updatePassword **(Deprecated)** | The parameter `currentPassword` is optional if you have `config.check_current_password_before_update` set to false (disabled by default) on your generated `config/initializers/devise_token_aut.rb` or if the `resource` model supports the `recoverable` Devise plugin and the `resource`'s `allow_password_change` attribute is set to true (this is done in the `userCheckPasswordToken` query when you click on the sent email's link). **This mutation is part of the first and soon to be deprecated password reset flow.** | userUpdatePassword(password: String!, passwordConfirmation: String!, currentPassword: String): UserUpdatePasswordPayload |
583
-
584
-
#### Queries
585
-
Operation | Description | Example
586
-
:--- | :--- | :------------------:
587
-
confirmAccount **(Deprecated)** | Performs a redirect using the `redirectUrl` param | userConfirmAccount(confirmationToken: String!, redirectUrl: String!): User
588
-
checkPasswordToken **(Deprecated)** | Performs a redirect using the `redirectUrl` param | userCheckPasswordToken(resetPasswordToken: String!, redirectUrl: String): User
589
-
590
-
The reason for having 2 queries is that these 2 are going to be accessed when clicking on
591
-
the confirmation and reset password email urls. There is no limitation for making mutation
592
-
requests using the `GET` method on the Rails side, but looks like there might be a limitation
593
-
on the [Apollo Client](https://www.apollographql.com/docs/apollo-server/v1/requests/#get-requests).
594
-
595
-
We will continue to build better docs for the gem after this first release, but in the mean time
596
-
you can use [our specs](spec/requests) to better understand how to use the gem.
597
-
Also, the [dummy app](spec/dummy) used in our specs will give you
598
-
a clear idea on how to configure the gem on your Rails application.
599
461
600
462
### Reset Password Flow
601
463
This gem supports two password recovery flows. The most recently implemented is preferred and
@@ -661,6 +523,11 @@ We will continue to improve the gem and add better docs.
661
523
1. Add support for unlockable and other Devise modules.
662
524
1. Add feature specs for confirm account and reset password flows.
663
525
526
+
We will continue to build better docs for the gem after this first release, but in the mean time
527
+
you can use [our specs](spec/requests) to better understand how to use the gem.
528
+
Also, the [dummy app](spec/dummy) used in our specs will give you
529
+
a clear idea on how to configure the gem on your Rails application.
530
+
664
531
## Contributing
665
532
666
533
Bug reports and pull requests are welcome on GitHub at https://github.com/graphql-devise/graphql_devise.
0 commit comments