Class: GraphqlDevise::Mutations::UpdatePasswordWithToken

Inherits:
Base
  • Object
show all
Defined in:
lib/graphql_devise/mutations/update_password_with_token.rb

Instance Method Summary collapse

Instance Method Details

#resolve(reset_password_token:, **attrs) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/graphql_devise/mutations/update_password_with_token.rb', line 15

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'),
      resource: resource
    )
  end
end