Sha256: 126837b4f616c15884fe99c1fdc140b8a00fd5f51a6c7895b9cebcfcde40d38a

Contents?: true

Size: 1.51 KB

Versions: 8

Compression:

Stored size: 1.51 KB

Contents

# frozen_string_literal: true

module Ibrain::Auth::Mutations
  class SignUpMutation < BaseMutation
    field :is_verified, Boolean, null: true
    field :result, Boolean, null: true

    argument :attributes, Ibrain::Auth::Config.sign_up_input, required: true
    argument :device_token, String, description: 'Device token for notificaiton', required: false

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

      sign_in(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
    end

    private

    def load_resource
      repo.create
    end

    def repo
      ::AuthRepository.new(nil, normalize_parameters)
    end

    def normalize_parameters
      attribute_params
    rescue StandardError
      ActionController::Parameters.new({})
    end

    def auth_options
      { scope: resource_name }
    end

    def graphql_returning
      OpenStruct.new(
        result: current_user.present?,
        is_verified: false
      )
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ibrain-auth-0.3.7 app/graphql/ibrain/auth/mutations/sign_up_mutation.rb
ibrain-auth-0.3.6 app/graphql/ibrain/auth/mutations/sign_up_mutation.rb
ibrain-auth-0.3.5 app/graphql/ibrain/auth/mutations/sign_up_mutation.rb
ibrain-auth-0.3.4 app/graphql/ibrain/auth/mutations/sign_up_mutation.rb
ibrain-auth-0.3.3 app/graphql/ibrain/auth/mutations/sign_up_mutation.rb
ibrain-auth-0.3.2 app/graphql/ibrain/auth/mutations/sign_up_mutation.rb
ibrain-auth-0.3.1 app/graphql/ibrain/auth/mutations/sign_up_mutation.rb
ibrain-auth-0.2.9 app/graphql/ibrain/auth/mutations/sign_up_mutation.rb