Module: StandardId::Passwordless

Defined in:
lib/standard_id/passwordless.rb,
lib/standard_id/passwordless/sms_strategy.rb,
lib/standard_id/passwordless/base_strategy.rb,
lib/standard_id/passwordless/email_strategy.rb,
lib/standard_id/passwordless/verification_service.rb

Defined Under Namespace

Classes: BaseStrategy, EmailStrategy, SmsStrategy, VerificationService

Class Method Summary collapse

Class Method Details

.verify(username:, code:, connection:, request:, allow_registration: true) ⇒ VerificationService::Result

Public API for verifying a passwordless OTP code.

This is the recommended entry point for host apps that need OTP verification without mounting WebEngine. It wraps VerificationService.verify with the same interface and result type.

Examples:

result = StandardId::Passwordless.verify(
  username: "user@example.com",
  code: "123456",
  connection: "email",
  request: request
)

if result.success?
  (result.)
else
  case result.error_code
  when :invalid_code then render_invalid_code
  when :expired      then render_expired
  when :max_attempts then render_locked_out
  when :not_found    then render_not_found
  end
end

Parameters:

  • username (String)

    The identifier value (email or phone number)

  • code (String)

    The OTP code to verify

  • connection (String)

    Channel type (“email” or “sms”)

  • request (ActionDispatch::Request)

    The current request

Returns:

  • (VerificationService::Result)

    A result with:

    • success? — true when verification succeeded

    • account — the authenticated/created account (nil on failure)

    • challenge — the consumed CodeChallenge (nil on failure)

    • error — human-readable message (nil on success)

    • error_code — machine-readable symbol (nil on success):

      :invalid_code, :expired, :max_attempts, :not_found, :blank_code,
      :account_not_found, :server_error
      
    • attempts — failed attempt count (nil on success)



45
46
47
48
49
50
51
52
53
# File 'lib/standard_id/passwordless.rb', line 45

def verify(username:, code:, connection:, request:, allow_registration: true)
  VerificationService.verify(
    connection: connection,
    username: username,
    code: code,
    request: request,
    allow_registration: allow_registration
  )
end