Sha256: 39741b768445379d442e92d5703bb8e498eb55c4dd78dbcc4e965ec7d7c716d1

Contents?: true

Size: 1.47 KB

Versions: 11

Compression:

Stored size: 1.47 KB

Contents

# frozen_string_literal: true

module GraphqlDevise
  module Mutations
    class UpdatePasswordWithToken < Base
      argument :password,              String, required: true
      argument :password_confirmation, String, required: true
      argument :reset_password_token,  String, required: true

      field :credentials,
            GraphqlDevise::Types::CredentialType,
            null:        true,
            description: 'Authentication credentials. Resource must be signed_in for credentials to be returned.'

      def resolve(reset_password_token:, **attrs)
        raise_user_error(I18n.t('graphql_devise.passwords.password_recovery_disabled')) unless recoverable_enabled?

        resource = resource_class.with_reset_password_token(reset_password_token)
        raise_user_error(I18n.t('graphql_devise.passwords.reset_token_not_found')) if resource.blank?
        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?

          response_payload               = { authenticatable: resource }
          response_payload[:credentials] = set_auth_headers(resource) if controller.signed_in?(resource_name)

          response_payload
        else
          raise_user_error_list(
            I18n.t('graphql_devise.passwords.update_password_error'),
            errors: resource.errors.full_messages
          )
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
graphql_devise-0.18.2 lib/graphql_devise/mutations/update_password_with_token.rb
graphql_devise-0.18.1 lib/graphql_devise/mutations/update_password_with_token.rb
graphql_devise-0.18.0 lib/graphql_devise/mutations/update_password_with_token.rb
graphql_devise-0.17.1 lib/graphql_devise/mutations/update_password_with_token.rb
graphql_devise-0.17.0 lib/graphql_devise/mutations/update_password_with_token.rb
graphql_devise-0.16.0 lib/graphql_devise/mutations/update_password_with_token.rb
graphql_devise-0.15.0 lib/graphql_devise/mutations/update_password_with_token.rb
graphql_devise-0.14.3 lib/graphql_devise/mutations/update_password_with_token.rb
graphql_devise-0.14.2 lib/graphql_devise/mutations/update_password_with_token.rb
graphql_devise-0.14.1 lib/graphql_devise/mutations/update_password_with_token.rb
graphql_devise-0.14.0 lib/graphql_devise/mutations/update_password_with_token.rb