Sha256: 3d74c388922adb15b94206f4c6a17978c8e51fa8e75562b0bad2924f251e092a

Contents?: true

Size: 1.84 KB

Versions: 4

Compression:

Stored size: 1.84 KB

Contents

module GraphqlDevise
  module Mutations
    class SignUp < Base
      argument :email,                 String, required: true
      argument :password,              String, required: true
      argument :password_confirmation, String, required: true
      argument :confirm_success_url,   String, required: false

      def resolve(confirm_success_url: nil, **attrs)
        resource = resource_class.new(provider: provider, **attrs)
        raise_user_error(I18n.t('graphql_devise.resource_build_failed')) if resource.blank?

        redirect_url = confirm_success_url || DeviseTokenAuth.default_confirm_success_url
        if confirmable_enabled? && redirect_url.blank?
          raise_user_error(I18n.t('graphql_devise.registrations.missing_confirm_redirect_url'))
        end

        if blacklisted_redirect_url?(redirect_url)
          raise_user_error(I18n.t('graphql_devise.registrations.redirect_url_not_allowed', redirect_url: redirect_url))
        end

        resource.skip_confirmation_notification! if resource.respond_to?(:skip_confirmation_notification!)

        if resource.save
          yield resource if block_given?

          unless resource.confirmed?
            resource.send_confirmation_instructions(
              redirect_url:  confirm_success_url,
              template_path: ['graphql_devise/mailer']
            )
          end

          set_auth_headers(resource) if resource.active_for_authentication?

          { authenticable: resource }
        else
          clean_up_passwords(resource)
          raise_user_error_list(
            I18n.t('graphql_devise.registration_failed'),
            errors: resource.errors.full_messages
          )
        end
      end

      private

      def provider
        :email
      end

      def clean_up_passwords(resource)
        controller.send(:clean_up_passwords, resource)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
graphql_devise-0.7.0 app/graphql/graphql_devise/mutations/sign_up.rb
graphql_devise-0.6.0 app/graphql/graphql_devise/mutations/sign_up.rb
graphql_devise-0.5.0 app/graphql/graphql_devise/mutations/sign_up.rb
graphql_devise-0.4.1 app/graphql/graphql_devise/mutations/sign_up.rb