provider = $provider; } /** * Enable two factor authentication for the user by generating secrets * and storing them temporarily in the session. * * @param mixed $user * @return void */ public function __invoke($user) { $secretKey = $this->provider->generateSecretKey(); $recoveryCodes = collect(range(1, 8)) ->map(fn () => Str::random(10).'-'.Str::random(10)) ->all(); $qrCodeSvg = $this->provider->qrCodeSvg( config('app.name'), $user->email, $secretKey ); // Store the generated data in the session session([ '2fa_setup_secret' => $secretKey, // Unencrypted secret for display and confirmation '2fa_setup_qr_svg' => $qrCodeSvg, '2fa_setup_recovery_codes' => encrypt(json_encode($recoveryCodes)), // Encrypt for storage in session ]); // IMPORTANT: This custom action does NOT save anything to the user model in the database. // That will be handled by the custom ConfirmTwoFactorAuthentication action. } }