Skip to content

Commit ef879dc

Browse files
committed
Document second password reset flow [ci skip]
1 parent 843c4e8 commit ef879dc

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -461,11 +461,11 @@ Operation | Description | Example
461461
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
462462
logout | | userLogout: UserLogoutPayload
463463
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
464+
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
465+
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
466+
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
464467
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
465468
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
466-
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
469469

470470
#### Queries
471471
Operation | Description | Example

docs/usage/reset_password_flow.md

+41-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ to return a redirect on the response. Flow 2 might be deprecated in the future.
88
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.
99

1010
### 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
11+
This mutation 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
1212
for authentication is `User`:
1313
```graphql
1414
mutation {
@@ -48,3 +48,43 @@ on how to extend the default behavior of mutations, but
4848
[here](https://github.com/graphql-devise/graphql_devise/blob/8c7c8a5ff1b35fb026e4c9499c70dc5f90b9187a/spec/dummy/app/graphql/mutations/reset_admin_password_with_token.rb)
4949
you can find an example mutation on what needs to be done in order for the mutation to return
5050
credentials after updating the password.
51+
52+
## Flow 2 (Deprecated)
53+
This was the first flow to be implemented, requires an additional step and also to encode a GQL query in a url, so this is not the preferred method.
54+
Each step name refers to the operation name you can use in the mount options to skip or override.
55+
56+
### 1. send_password_reset
57+
This mutation 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
58+
for authentication is `User`:
59+
```graphql
60+
mutation {
61+
userSendPasswordReset(
62+
63+
redirectUrl: "https://google.com"
64+
) {
65+
message
66+
}
67+
}
68+
```
69+
The email will contain an encoded GraphQL query that holds the reset token and redirectUrl.
70+
The query is described in the next step.
71+
72+
### 2. check_password_token
73+
This query checks the reset password token and if successful changes a column in the DB (`allow_password_change`) to true.
74+
This change will allow for the next step to update the password without providing the current password.
75+
Then, this query will redirect to the provided `redirectUrl` with credentials.
76+
77+
### 3. update_password
78+
This step requires the request to include authentication headers and will allow the user to
79+
update the password if step 2 was successful.
80+
Here's an example assuming the resource used for authentication is `User`:
81+
```graphql
82+
mutation {
83+
userUpdatePassword(
84+
password: "password123",
85+
passwordConfirmation: "password123"
86+
) {
87+
authenticatable { email }
88+
}
89+
}
90+
```

0 commit comments

Comments
 (0)