PhoneVerificationController

class PhoneVerificationController(handler: PhoneNumberVerificationHandler, currentTimeMillis: () -> Long = ::currentEpochMillis)(source)

Sequences PhoneNumberVerificationHandler calls and exposes the result as a single observable PhoneVerificationState.

This is where the rules that are easy to get wrong live:

  • only a number with PhoneNumberValue.isValid can start verification;

  • a request in flight blocks a second one, so double-tapping "Send code" sends one SMS;

  • resend is refused until the handler's cooldown elapses;

  • editing the number invalidates any verification already obtained — see onPhoneNumberChanged.

The controller is UI-framework-agnostic apart from holding its state in a Compose mutableStateOf; it contains no composables and can be driven from a ViewModel just as easily. Every method is suspend and does its work on the caller's dispatcher — nothing here blocks the main thread, and no coroutine is launched internally, so cancellation is the caller's to control.

Constructors

Link copied to clipboard
constructor(handler: PhoneNumberVerificationHandler, currentTimeMillis: () -> Long = ::currentEpochMillis)

Properties

Link copied to clipboard

The current verification state. Observe this from composition.

Functions

Link copied to clipboard

True when phoneNumber is the number that was successfully verified.

Link copied to clipboard

Tells the controller the field's number changed.

Link copied to clipboard
suspend fun requestCode(phoneNumber: PhoneNumberValue)

Starts verification for phoneNumber.

Link copied to clipboard

Seconds remaining before a resend is allowed; 0 when it is allowed now.

Link copied to clipboard
suspend fun resendCode()

Re-sends the code for the active challenge.

Link copied to clipboard
fun reset()

Clears all verification state, e.g. when a form is reset.

Link copied to clipboard
suspend fun submitCode(code: String)

Submits code against the active challenge.