Skip to content

Alternate reset password flow, only 2 steps, no redirect#146

Merged
mcelicalderon merged 3 commits intomasterfrom
alternate-reset-password-flow
Jan 19, 2021
Merged

Alternate reset password flow, only 2 steps, no redirect#146
mcelicalderon merged 3 commits intomasterfrom
alternate-reset-password-flow

Conversation

@mcelicalderon
Copy link
Copy Markdown
Member

@mcelicalderon mcelicalderon commented Jan 15, 2021

Implements a different reset password flow. Now a mutation will send an email with a link to the provided url (front end) on the mutation containing a reset password token. It's the client responsibility to get this token and then call another mutation that takes the new password and the token. This mutation changes the password and returns credentials if the resource is signed in. The new mutations are:

  • sendPasswordResetWithToken: Takes email and redirectUrl. Sends an email with a reset link that simply uses that redirectUrl and adds a reset password token as query params. On you frontend application you will use that token to call the second mutation.
  • updatePasswordWithToken: Takes the resetPasswordToken, password and passwordConfirmation. Simply allows you to update the password of a user by sending the token. You can do this if you want to return authentication credentials after the password is changed, it won't return those by default.

Resolves #133

field :credentials,
GraphqlDevise::Types::CredentialType,
null: true,
description: 'Authentication credentials. Resource must be signed_in in order for credentials to be returned.'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about Authentication credentials. Resource must be signed_in for credentials to be returned. ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, makes more sense

raise_user_error(I18n.t('graphql_devise.passwords.reset_token_expired')) unless resource.reset_password_period_valid?

if resource.update(attrs)
yield resource if block_given?
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What kind of black can be passed here? Is there any examples of this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any block you want, all mutations do the same. Check the specs in this PR for an example.

@mcelicalderon mcelicalderon marked this pull request as ready for review January 19, 2021 03:53
expect do
post_request
admin.reload
end.to change(admin, :encrypted_password)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WDYT about checking the password is valid instead of encrypted_password being changed?

@mcelicalderon mcelicalderon merged commit 6e56f3f into master Jan 19, 2021
@mcelicalderon mcelicalderon deleted the alternate-reset-password-flow branch January 19, 2021 15:57
@mcelicalderon mcelicalderon added the enhancement New feature or request label Jan 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

userCheckPasswordToken return Type

2 participants