Class: Ibrain::Auth::Mutations::SignUpMutation

Inherits:
BaseMutation
  • Object
show all
Defined in:
app/graphql/ibrain/auth/mutations/sign_up_mutation.rb

Instance Method Summary collapse

Methods inherited from BaseMutation

#_prefixes, #ready?

Instance Method Details

#resolve(args) ⇒ Object



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 'app/graphql/ibrain/auth/mutations/sign_up_mutation.rb', line 12

def resolve(args)
  # TODO: define logic inside repository
  return graphql_returning(false, false) if auth_resource.blank?

  (resource_name, auth_resource)
  @current_user = warden.authenticate!(auth_options)

  warden.set_user(current_user)
  current_user.jwt_token, jti = auth_headers(request, auth_resource)

  current_user.jti = jti
  current_user.save!

  if args[:device_token].present?
    device_token = current_user.device_tokens.find_by(token: args[:device_token])

    current_user.device_tokens.create!({ token: args[:device_token] }) if device_token.blank?
  end

  context[:current_user] = current_user

  graphql_returning(
    user_signed_in?,
    true,
    user_signed_in? ? current_user : nil,
    current_user.try(:jwt_token),
  )
end