Skip to content

Commit e5c8b58

Browse files
committed
renaming and re-organizing
1 parent 2fe16e3 commit e5c8b58

File tree

6 files changed

+26
-138
lines changed

6 files changed

+26
-138
lines changed

app/Http/Controllers/Auth/TwoFactorAuthenticatedSessionController.php

Lines changed: 0 additions & 112 deletions
This file was deleted.

app/Http/Controllers/Settings/TwoFactorAuthController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ class TwoFactorAuthController extends Controller
2323
public function edit(Request $request)
2424
{
2525
return Inertia::render('settings/two-factor', [
26-
'enabled' => $this->twoFactorEnabled($request->user()),
2726
'confirmed' => !is_null($request->user()->two_factor_confirmed_at),
2827
'recoveryCodes' => $this->getRecoveryCodes($request->user()),
2928
]);

resources/css/app.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@
111111
--sidebar-accent-foreground: oklch(0.205 0 0);
112112
--sidebar-border: oklch(0.922 0 0);
113113
--sidebar-ring: oklch(0.87 0 0);
114+
115+
/* Allows us to transition an element from a certain length to its intrinsic size */
116+
/* Learn more here: https://css-tricks.com/almanac/properties/i/interpolate-size/ */
117+
interpolate-size: allow-keywords;
114118
}
115119

116120
.dark {

resources/js/pages/settings/two-factor.tsx

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,17 @@ const breadcrumbs: BreadcrumbItem[] = [
1818
];
1919

2020
interface TwoFactorProps {
21-
enabled: boolean;
2221
confirmed: boolean;
23-
qrCode: boolean;
2422
recoveryCodes: string[];
2523
}
2624

27-
export default function TwoFactor({ enabled: initialEnabled, confirmed: initialConfirmed, qrCode, recoveryCodes }: TwoFactorProps) {
28-
const [enabled, setEnabled] = useState(initialEnabled);
25+
export default function TwoFactor({ confirmed: initialConfirmed, recoveryCodes }: TwoFactorProps) {
2926
const [confirmed, setConfirmed] = useState(initialConfirmed);
3027
const [showModal, setShowModal] = useState(false);
3128
const [verifyStep, setVerifyStep] = useState(false);
3229
const [qrCodeSvg, setQrCodeSvg] = useState('');
3330
const [secretKey, setSecretKey] = useState('');
34-
const [showingRecoveryCodes, setShowingRecoveryCodes] = useState(initialEnabled);
31+
const [showingRecoveryCodes, setShowingRecoveryCodes] = useState(false);
3532
const [recoveryCodesList, setRecoveryCodesList] = useState(recoveryCodes);
3633
const [copied, setCopied] = useState(false);
3734

@@ -51,7 +48,6 @@ export default function TwoFactor({ enabled: initialEnabled, confirmed: initialC
5148
preserveScroll: true,
5249
onSuccess: async () => {
5350
// Only set enabled to true, but not confirmed yet
54-
setEnabled(true);
5551
const response = await fetch(route('two-factor.qr-code'));
5652
const data = await response.json();
5753
setQrCodeSvg(data.svg);
@@ -117,7 +113,6 @@ export default function TwoFactor({ enabled: initialEnabled, confirmed: initialC
117113
destroy(route('two-factor.disable'), {
118114
preserveScroll: true,
119115
onSuccess: () => {
120-
setEnabled(false);
121116
setConfirmed(false);
122117
setShowingRecoveryCodes(false);
123118
setQrCodeSvg('');
@@ -319,18 +314,22 @@ export default function TwoFactor({ enabled: initialEnabled, confirmed: initialC
319314
</Button>
320315
)}
321316
</div>
322-
{showingRecoveryCodes && (
323-
<div className="relative">
324-
<div className="grid max-w-xl gap-1 px-4 py-4 font-mono text-sm bg-stone-200 dark:bg-stone-900 dark:text-stone-100">
325-
{recoveryCodesList.map((code, index) => (
326-
<div key={index}>{code}</div>
327-
))}
328-
</div>
329-
<p className="px-4 py-3 text-xs select-none text-stone-500 dark:text-stone-400">
330-
You have {recoveryCodesList.length} recovery codes left. Each can be used once to access your account and will be removed after use. If you need more, click <span className="font-bold">Regenerate Codes</span> above.
331-
</p>
317+
<div
318+
className="relative overflow-hidden transition-all duration-300"
319+
style={{
320+
height: showingRecoveryCodes ? 'auto' : '0',
321+
opacity: showingRecoveryCodes ? 1 : 0,
322+
}}
323+
>
324+
<div className="grid max-w-xl gap-1 px-4 py-4 font-mono text-sm bg-stone-200 dark:bg-stone-900 dark:text-stone-100">
325+
{recoveryCodesList.map((code, index) => (
326+
<div key={index}>{code}</div>
327+
))}
332328
</div>
333-
)}
329+
<p className="px-4 py-3 text-xs select-none text-stone-500 dark:text-stone-400">
330+
You have {recoveryCodesList.length} recovery codes left. Each can be used once to access your account and will be removed after use. If you need more, click <span className="font-bold">Regenerate Codes</span> above.
331+
</p>
332+
</div>
334333
</div>
335334
</div>
336335
<div className="inline relative">

routes/auth.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use App\Http\Controllers\Auth\PasswordResetLinkController;
99
use App\Http\Controllers\Auth\RegisteredUserController;
1010
use App\Http\Controllers\Auth\VerifyEmailController;
11-
use App\Http\Controllers\Auth\TwoFactorAuthenticatedSessionController;
11+
use App\Http\Controllers\Auth\TwoFactorAuthChallengeController;
1212
use Illuminate\Support\Facades\Route;
1313

1414
Route::middleware('guest')->group(function () {
@@ -58,8 +58,8 @@
5858

5959
// Two-factor challenge routes with the ensure-two-factor-challenge-session middleware
6060
Route::middleware('ensure-two-factor-challenge-session')->group(function () {
61-
Route::get('two-factor-challenge', [TwoFactorAuthenticatedSessionController::class, 'create'])
61+
Route::get('two-factor-challenge', [TwoFactorAuthChallengeController::class, 'create'])
6262
->name('two-factor.challenge');
6363

64-
Route::post('two-factor-challenge', [TwoFactorAuthenticatedSessionController::class, 'store']);
64+
Route::post('two-factor-challenge', [TwoFactorAuthChallengeController::class, 'store']);
6565
});

tests/Feature/Auth/TwoFactorAuthTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,8 @@ public function test_can_view_two_factor_settings_page()
2727
$inertiaProps = $response->original?->getData() ?? [];
2828
if (isset($inertiaProps['page']['props'])) {
2929
$props = $inertiaProps['page']['props'];
30-
$this->assertArrayHasKey('enabled', $props);
3130
$this->assertArrayHasKey('confirmed', $props);
3231
$this->assertArrayHasKey('recoveryCodes', $props);
33-
$this->assertFalse($props['enabled']);
3432
$this->assertFalse($props['confirmed']);
3533
} else {
3634
// Fallback: check for expected strings in HTML (legacy/SSR)
@@ -82,8 +80,8 @@ public function test_can_manually_enable_two_factor_authentication()
8280
if (isset($inertiaProps['page']['props'])) {
8381
$props = $inertiaProps['page']['props'];
8482
$this->assertTrue(
85-
($props['enabled'] ?? false) === true,
86-
'2FA should be enabled in page props.'
83+
($props['confirmed'] ?? false) === true,
84+
'2FA should be confirmed in page props.'
8785
);
8886
$this->assertArrayHasKey('recoveryCodes', $props);
8987
} else {

0 commit comments

Comments
 (0)