feat: add two-factor authentication support and related configurations
This commit is contained in:
40
app/Http/Controllers/ProfileController.php
Normal file
40
app/Http/Controllers/ProfileController.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
use Laravel\Fortify\Fortify;
|
||||
|
||||
class ProfileController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the authenticated user's profile and security settings.
|
||||
*/
|
||||
public function __invoke(Request $request): Response
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = $request->user();
|
||||
$available = (bool) config('auth-ui.features.two_factor');
|
||||
$pending = $available
|
||||
&& filled($user->two_factor_secret)
|
||||
&& ! $user->hasEnabledTwoFactorAuthentication();
|
||||
|
||||
return Inertia::render('Profile/Show', [
|
||||
'twoFactor' => [
|
||||
'available' => $available,
|
||||
'enabled' => $available && $user->hasEnabledTwoFactorAuthentication(),
|
||||
'pending' => $pending,
|
||||
'requiresPassword' => $user->hasPassword(),
|
||||
'qrCodeDataUri' => $pending
|
||||
? 'data:image/svg+xml;base64,'.base64_encode($user->twoFactorQrCodeSvg())
|
||||
: null,
|
||||
'secretKey' => $pending
|
||||
? Fortify::currentEncrypter()->decrypt($user->two_factor_secret)
|
||||
: null,
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user