Sha256: adfdc2b6e5a88d060be4f5bb5618349ffe727f457f3056c5f0184d91d4a66dea

Contents?: true

Size: 1.46 KB

Versions: 5

Compression:

Stored size: 1.46 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,
            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] = generate_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

5 entries across 5 versions & 1 rubygems

Version Path
graphql_devise-1.3.0 lib/graphql_devise/mutations/update_password_with_token.rb
graphql_devise-1.2.0 lib/graphql_devise/mutations/update_password_with_token.rb
graphql_devise-1.1.1 lib/graphql_devise/mutations/update_password_with_token.rb
graphql_devise-1.1.0 lib/graphql_devise/mutations/update_password_with_token.rb
graphql_devise-1.0.1 lib/graphql_devise/mutations/update_password_with_token.rb