User-two_factor_recovery_codes Tag
Recovery codes provide a backup way for users to access their account if they lose their authenticator device. This tag displays those codes.
Overview#
The user:two_factor_recovery_codes tag loops through and displays the authenticated user's recovery codes. Each recovery code can only be used once to log in if the user doesn't have access to their authenticator app.
Hot Tip!
This tag requires the user to be authenticated with 2FA enabled. If 2FA is not enabled, the tag won't render any content.
Example#
{{ if {user:two_factor_enabled} }}
<h2>Your Recovery Codes</h2>
<p>Store these codes in a safe place. Each code can only be used once.</p>
<ul class="recovery-codes">
{{ user:two_factor_recovery_codes }}
<li><code>{{ code }}</code></li>
{{ /user:two_factor_recovery_codes }}
</ul>
{{ else }}
<p>You don't have two-factor authentication enabled.</p>
{{ /if }}
@if (Statamic::tag('user:two_factor_enabled')->fetch())
<h2>Your Recovery Codes</h2>
<p>Store these codes in a safe place. Each code can only be used once.</p>
<ul class="recovery-codes">
<s:user:two_factor_recovery_codes>
<li><code>{{ $code }}</code></li>
</s:user:two_factor_recovery_codes>
</ul>
@else
<p>You don't have two-factor authentication enabled.</p>
@endif
Hot Tip!
{{ user:two_factor_enabled }} is a tag, not a variable, so conditionals need the extra braces: {{ if {user:two_factor_enabled} }}.
Variables
| Variable | Type | Description |
|---|---|---|
code |
string |
A single recovery code. |