View Source Appwrite.Consts.AuthenticationFactor (appwrite v0.1.9)

Provides constants and validation functions for different authentication factors.

This module defines the allowed authentication factors and provides helper functions to validate them. It ensures that only recognized authentication factors are used within the application.

Summary

Functions

Returns true if the given factor is a valid authentication factor, otherwise false.

Guard clause to check if a given factor is a valid authentication factor.

Validates the given factor and returns {:ok, factor} if it is valid, or {:error, "Invalid authentication factor"} otherwise.

Validates the given factor and returns it if it is valid. Raises an ArgumentError if the factor is invalid.

Functions

is_valid_factor?(factor)

@spec is_valid_factor?(String.t()) :: boolean()

Returns true if the given factor is a valid authentication factor, otherwise false.

Examples

iex> AuthenticationFactor.is_valid_factor?("totp")
true

iex> AuthenticationFactor.is_valid_factor?("unknown")
false

valid_factor(factor)

(macro)
@spec valid_factor(String.t()) :: boolean()

Guard clause to check if a given factor is a valid authentication factor.

Examples

iex> AuthenticationFactor.valid_factor("email")
true

iex> AuthenticationFactor.valid_factor("unknown")
false

validate_factor(factor)

@spec validate_factor(String.t()) :: {:ok, String.t()} | {:error, String.t()}

Validates the given factor and returns {:ok, factor} if it is valid, or {:error, "Invalid authentication factor"} otherwise.

Examples

iex> AuthenticationFactor.validate_factor("email")
{:ok, "email"}

iex> AuthenticationFactor.validate_factor("unknown")
{:error, "Invalid authentication factor"}

validate_factor!(factor)

@spec validate_factor!(String.t()) :: String.t()

Validates the given factor and returns it if it is valid. Raises an ArgumentError if the factor is invalid.

Examples

iex> AuthenticationFactor.validate_factor!("phone")
"phone"

iex> AuthenticationFactor.validate_factor!("unknown")
** (ArgumentError) Invalid authentication factor: "unknown"