Class: GraphqlDevise::Mutations::Login

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

Instance Method Summary collapse

Instance Method Details

#resolve(email:, password:) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/graphql_devise/mutations/login.rb', line 11

def resolve(email:, password:)
  resource = find_resource(
    :email,
    get_case_insensitive_field(:email, email)
  )

  if resource && active_for_authentication?(resource)
    if invalid_for_authentication?(resource, password)
      raise_user_error(I18n.t('graphql_devise.sessions.bad_credentials'))
    end

    new_headers = generate_auth_headers(resource)
    controller.(:user, resource, store: false, bypass: false)

    yield resource if block_given?

    context[:current_resource] = resource if context[:current_resource].nil?

    { authenticatable: resource, credentials: new_headers }
  elsif resource && !active_for_authentication?(resource)
    if locked?(resource)
      raise_user_error(I18n.t('graphql_devise.mailer.unlock_instructions.account_lock_msg'))
    else
      raise_user_error(I18n.t('graphql_devise.sessions.not_confirmed', email: resource.email))
    end
  else
    raise_user_error(I18n.t('graphql_devise.sessions.bad_credentials'))
  end
end