(Add) Button to copy 2fa recovery codes (#4874)

* Convert pre to div

Fix https://github.com/HDInnovations/UNIT3D/issues/4873

* Undo change to div and add copy button

* Get rid of init wait

* Put script first

* Directly define function

* Revert "Directly define function"

This reverts commit 629248a6a5.

* Revert "Put script first"

This reverts commit b1d8ac894b.

* Revert "Get rid of init wait"

This reverts commit 79d77ab8ab.

* Remove dash

* Finally fix

* Use two words with underscore

* Run prettier

* automation: prettier blade ci

* Apply suggestion from @PythonCoderAS

---------

Co-authored-by: HDVinnie <hdinnovations@protonmail.com>
Co-authored-by: unit3d-bot <unit3d_gh_bot@protonmail.com>
This commit is contained in:
PythonCoderAS
2026-01-27 03:45:00 -05:00
committed by GitHub
parent d51225b77e
commit a11d9e22f1
@@ -101,6 +101,39 @@
>
{{ __('Regenerate Recovery Codes') }}
</button>
@script
<script
nonce="{{ HDVinnie\SecureHeaders\SecureHeaders::nonce('script') }}"
>
Alpine.data('recovery_codes', () => ({
copy() {
navigator.clipboard.writeText(
JSON.parse(
atob(
'{{ base64_encode(decrypt($this->user->two_factor_recovery_codes)) }}',
),
).join('\n'),
);
Swal.fire({
toast: true,
position: 'top-end',
showConfirmButton: false,
timer: 3000,
icon: 'success',
title: 'Copied to clipboard!',
});
},
}));
</script>
@endscript
<button
class="form__button form__button--filled"
x-data="recovery_codes"
x-on:click.stop="copy"
>
{{ __('Copy Recovery Codes') }}
</button>
@elseif ($showingConfirmation)
<button
class="form__button form__button--filled"