AshAuthentication.Phoenix.RecoveryCodeHelpers (ash_authentication_phoenix v3.0.0-rc.6)

View Source

Helper functions for working with recovery code authentication.

These helpers can be used in plugs, LiveView on_mount hooks, and templates to check if a user has recovery codes configured.

Usage in Templates

<%= if AshAuthentication.Phoenix.RecoveryCodeHelpers.recovery_codes_configured?(@current_user) do %>
  <span>Recovery codes enabled</span>
<% end %>

Summary

Functions

Returns the recovery code strategy for a resource.

Returns true if recovery codes are available for the given resource.

Returns true if the user has recovery codes configured.

Functions

get_recovery_code_strategy(resource, opts \\ [])

@spec get_recovery_code_strategy(
  module(),
  keyword()
) :: {:ok, struct()} | {:error, :no_recovery_code_strategy}

Returns the recovery code strategy for a resource.

Options

  • :strategy - The specific strategy name to look for. If not provided, returns the first recovery code strategy found.

recovery_code_available?(resource)

@spec recovery_code_available?(module()) :: boolean()

Returns true if recovery codes are available for the given resource.

recovery_codes_configured?(user, opts \\ [])

@spec recovery_codes_configured?(
  Ash.Resource.record(),
  keyword()
) :: boolean()

Returns true if the user has recovery codes configured.

This checks if the user has any recovery codes by loading the configured relationship and checking if it is non-empty.

Options

  • :strategy - The recovery code strategy to check against. If not provided, the first recovery code strategy for the resource will be used.