PasskeyResult

sealed interface PasskeyResult<out T>

Outcome of a passkey operation: either Success with a value or Failure with a typed PasskeyError.

Closed: it is always one of these two; a when over it needs no else branch.

Samples

passkeys.signIn(server.authenticationOptions()).fold(
        onSuccess = { server.finishSignIn(it.json); SignInState.SignedIn },
        onFailure = { if (it.isUserCancellation) SignInState.Idle else SignInState.Failed(it.message) },
    )

Inheritors

Types

Link copied to clipboard
data class Failure(val error: PasskeyError) : PasskeyResult<Nothing>

The operation failed; error says why.

Link copied to clipboard
data class Success<out T>(val value: T) : PasskeyResult<T>

The operation succeeded; value is the result.

Properties

Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard

Returns the error on failure, or null on success.

Link copied to clipboard
inline fun <T, R> PasskeyResult<T>.fold(onSuccess: (T) -> R, onFailure: (PasskeyError) -> R): R

Returns onSuccess of the value or onFailure of the error; exactly one of them runs. The usual way to turn a result into your own type:

Link copied to clipboard

Returns the value on success, or null on failure.

Link copied to clipboard

Returns the value on success, or throws a PasskeyException carrying the error.

Link copied to clipboard
inline fun <T, R> PasskeyResult<T>.map(transform: (T) -> R): PasskeyResult<R>

Transforms the value on success; failures pass through unchanged.

Link copied to clipboard

Transforms the error on failure, e.g. into another PasskeyError; successes pass through unchanged.

Link copied to clipboard
inline fun <T> PasskeyResult<T>.onFailure(action: (PasskeyError) -> Unit): PasskeyResult<T>

Runs action with the error if this is a PasskeyResult.Failure; returns this result unchanged.

Link copied to clipboard
inline fun <T> PasskeyResult<T>.onSuccess(action: (T) -> Unit): PasskeyResult<T>

Runs action with the value if this is a PasskeyResult.Success; returns this result unchanged.

Link copied to clipboard
inline fun <T> PasskeyResult<T>.recover(transform: (PasskeyError) -> T): PasskeyResult<T>

Turns any failure into a success with transform's value; successes pass through unchanged. It hides setup errors too, so log them in transform (or use fold when failures need their own handling):

Link copied to clipboard

The same outcome as a kotlin.Result; a failure holds a PasskeyException whose error is the original error. For code built around Result (e.g. runCatching chains).