Skip to content

Commit cae3c55

Browse files
committed
refactor: centralize two-factor authentication logic, improve UI state and
1 parent ebda2c6 commit cae3c55

File tree

3 files changed

+117
-84
lines changed

3 files changed

+117
-84
lines changed

app/Http/Controllers/Settings/TwoFactorAuthenticationController.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
namespace App\Http\Controllers\Settings;
44

5+
use App\Http\Controllers\Concerns\ConfirmsTwoFactorAuthentication;
56
use App\Http\Controllers\Controller;
6-
use App\Models\User;
77
use Illuminate\Http\Request;
88
use Inertia\Inertia;
99
use Inertia\Response;
10-
use App\Http\Controllers\Concerns\ConfirmsTwoFactorAuthentication;
10+
use Laravel\Fortify\Features;
1111

1212
class TwoFactorAuthenticationController extends Controller
1313
{
@@ -20,16 +20,9 @@ public function show(Request $request): Response
2020
{
2121
$this->validateTwoFactorAuthenticationState($request);
2222

23-
/** @var User $user */
24-
$user = $request->user();
25-
26-
$confirmed = filled($user->two_factor_confirmed_at);
27-
2823
return Inertia::render('settings/TwoFactor', [
29-
'confirmed' => $confirmed,
30-
'recoveryCodes' => filled($user->two_factor_secret) ? json_decode(decrypt($user->two_factor_recovery_codes)) : [],
31-
'qrCodeSvg' => !$confirmed && filled($user->two_factor_secret) ? $user->twoFactorQrCodeSvg() : null,
32-
'secretKey' => !$confirmed && filled($user->two_factor_secret) ? decrypt($user->two_factor_secret) : null,
24+
'requiresConfirmation' => Features::optionEnabled(Features::twoFactorAuthentication(), 'confirm'),
25+
'twoFactorEnabled' => filled($request->user()->two_factor_confirmed_at),
3326
]);
3427
}
3528
}

0 commit comments

Comments
 (0)