Skip to content

Commit 843c4e8

Browse files
committed
Document first and most recent password reset flow [ci skip]
1 parent 8c7c8a5 commit 843c4e8

File tree

2 files changed

+65
-5
lines changed

2 files changed

+65
-5
lines changed

README.md

+15-5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ GraphQL interface on top of the [Devise Token Auth](https://github.com/lynndylan
3333
* [Making Requests](#making-requests)
3434
* [Mutations](#mutations)
3535
* [Queries](#queries)
36+
* [Reset Password Flow](#reset-password-flow)
3637
* [More Configuration Options](#more-configuration-options)
3738
* [Devise Token Auth Initializer](#devise-token-auth-initializer)
3839
* [Devise Initializer](#devise-initializer)
@@ -42,7 +43,7 @@ GraphQL interface on top of the [Devise Token Auth](https://github.com/lynndylan
4243
* [Contributing](#contributing)
4344
* [License](#license)
4445

45-
<!-- Added by: david, at: mar jul 14 08:08:02 -05 2020 -->
46+
<!-- Added by: mcelicalderon, at: Mon Jan 25 22:48:17 -05 2021 -->
4647

4748
<!--te-->
4849

@@ -288,10 +289,12 @@ The following is a list of the symbols you can provide to the `operations`, `ski
288289
:login
289290
:logout
290291
:sign_up
291-
:update_password
292-
:send_password_reset
293292
:confirm_account
293+
:send_password_reset
294294
:check_password_token
295+
:update_password
296+
:send_password_reset_with_token
297+
:update_password_with_token
295298
```
296299

297300
### Configuring Model
@@ -458,9 +461,11 @@ Operation | Description | Example
458461
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
459462
logout | | userLogout: UserLogoutPayload
460463
signUp | 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
461-
sendResetPassword | | userSendResetPassword(email: String!, redirectUrl: String!): UserSendReserPasswordPayload
462-
updatePassword | 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). | userUpdatePassword(password: String!, passwordConfirmation: String!, currentPassword: String): UserUpdatePasswordPayload
464+
sendResetPassword | 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!): UserSendReserPasswordPayload
465+
updatePassword | 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
463466
resendConfirmation | The `UserResendConfirmationPayload` will return the `authenticatable` resource that was sent the confirmation instructions but also has 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
467+
userSendPasswordResetWithToken | 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
468+
userUpdatePasswordWithToken | 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
464469

465470
#### Queries
466471
Operation | Description | Example
@@ -478,6 +483,11 @@ you can use [our specs](spec/requests) to better understand how to use the gem.
478483
Also, the [dummy app](spec/dummy) used in our specs will give you
479484
a clear idea on how to configure the gem on your Rails application.
480485

486+
### Reset Password Flow
487+
This gem supports two password recovery flows. The most recently implemented is preferred and
488+
requires less steps. More detail on how it works can be found
489+
[here](docs/usage/reset_password_flow.md).
490+
481491
### More Configuration Options
482492
As mentioned in the introduction there are many configurations that will change how this gem behaves. You can change
483493
this values on the initializer files generated by the installer.

docs/usage/reset_password_flow.md

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Reset Password Flow
2+
This gem supports two different ways to reset a password on a resource. Each password reset flow has it's own set of
3+
operations and this document will explain in more detail how to use each.
4+
The first and most recently implemented flow is preferred as it requires less steps and doesn't require a mutation
5+
to return a redirect on the response. Flow 2 might be deprecated in the future.
6+
7+
## Flow #1 (Preferred)
8+
This flow only has two steps. Each step name refers to the operation name you can use in the mount options to skip or override.
9+
10+
### 1. send_password_reset_with_token
11+
This operation on the gem will send an email to the specified address if it's found on the system. Returns an error if the email is not found. Here's an example assuming the resource used
12+
for authentication is `User`:
13+
```graphql
14+
mutation {
15+
userSendPasswordResetWithToken(
16+
17+
redirectUrl: "https://google.com"
18+
) {
19+
message
20+
}
21+
}
22+
```
23+
The email will contain a link to the `redirectUrl` (https://google.com in the example) and append a `reset_password_token` query param. This is the token you will
24+
need to use in the next step in order to reset the password.
25+
26+
### 2. update_password_with_token
27+
This mutation uses the token sent on the email to find the resource you are trying to recover.
28+
All you have to do is send a valid token together with the new password and password confirmation.
29+
Here's an example assuming the resource used for authentication is `User`:
30+
31+
```graphql
32+
mutation {
33+
userUpdatePasswordWithToken(
34+
resetPasswordToken: "token_here",
35+
password: "password123",
36+
passwordConfirmation: "password123"
37+
) {
38+
authenticatable { email }
39+
credentials { accessToken }
40+
}
41+
}
42+
```
43+
The mutation has two fields:
44+
1. `authenticatable`: Just like other mutations, returns the actual resource you just recover the password for.
45+
1. `credentials`: This is a nullable field. It will only return credentials as if you had just logged
46+
in into the app if you explicitly say so by overriding the mutation. The docs have more detail
47+
on how to extend the default behavior of mutations, but
48+
[here](https://github.com/graphql-devise/graphql_devise/blob/8c7c8a5ff1b35fb026e4c9499c70dc5f90b9187a/spec/dummy/app/graphql/mutations/reset_admin_password_with_token.rb)
49+
you can find an example mutation on what needs to be done in order for the mutation to return
50+
credentials after updating the password.

0 commit comments

Comments
 (0)