Class: Ibrain::Mutations::SignUpMutation

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

Instance Method Summary collapse

Methods inherited from AuthMutation

#_prefixes, #ready?

Instance Method Details

#resolve(_args) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/graphql/ibrain/mutations/sign_up_mutation.rb', line 11

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 params[:device_token].present?
    device_token = current_user.device_tokens.find_by(token: params[:device_token])

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

  context[:current_user] = current_user
  graphql_returning
end