Sha256: 0bfcb1882168f8edc86102d03b1dcdddfe3811463a75bce50e216214c534f841

Contents?: true

Size: 1.25 KB

Versions: 3

Compression:

Stored size: 1.25 KB

Contents

module Stytch
  module Endpoints
    module OTP
      PATH = "/v1/otp".freeze

      def send_otp_by_sms(
        phone_number:,
        expiration_minutes: nil,
        attributes: {}
      )
        request = {
          phone_number: phone_number,
          expiration_minutes: expiration_minutes,
        }

        request[:attributes] = attributes if attributes != {}

        post("#{PATH}/send_by_sms", request)
      end

      def login_or_create_user_by_sms(
        phone_number:,
        expiration_minutes: nil,
        attributes: {},
        create_user_as_pending: false
      )
        request = {
          phone_number: phone_number,
          expiration_minutes: expiration_minutes,
          create_user_as_pending: create_user_as_pending
        }

        request[:attributes] = attributes if attributes != {}

        post("#{PATH}/login_or_create", request)
      end

      def authenticate_otp(
        method_id:,
        code:,
        attributes: {},
        options: {}
      )
        request = {
          method_id: method_id,
          code: code,
        }

        request[:attributes] = attributes if attributes != {}
        request[:options] = options if options != {}

        post("#{PATH}/authenticate", request)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
stytch-1.0.0 lib/stytch/endpoints/otp.rb
stytch-0.2.1 lib/stytch/endpoints/otp.rb
stytch-0.2.0 lib/stytch/endpoints/otp.rb