Skip to content

Commit a5bbfee

Browse files
authored
[2.x] Fix error handling during 2FA confirmation (#1030)
* Prevent user reset when not yet finished confirming * Show correct message and error
1 parent df8e428 commit a5bbfee

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

Diff for: src/Http/Controllers/Inertia/Concerns/ConfirmsTwoFactorAuthentication.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ protected function hasJustBegunConfirmingTwoFactorAuthentication(Request $reques
7777
*/
7878
protected function neverFinishedConfirmingTwoFactorAuthentication(Request $request, $currentTime)
7979
{
80-
return is_null($request->user()->two_factor_confirmed_at) &&
80+
return ! array_key_exists('code', $request->session()->getOldInput()) &&
81+
is_null($request->user()->two_factor_confirmed_at) &&
8182
$request->session()->get('two_factor_confirming_at', 0) != $currentTime;
8283
}
8384
}

Diff for: stubs/inertia/resources/js/Pages/Profile/Partials/TwoFactorAuthenticationForm.vue

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup>
2-
import { ref, computed } from 'vue';
2+
import { ref, computed, watch } from 'vue';
33
import { Inertia } from '@inertiajs/inertia';
44
import { useForm, usePage } from '@inertiajs/inertia-vue3';
55
import JetActionSection from '@/Jetstream/ActionSection.vue';
@@ -30,6 +30,13 @@ const twoFactorEnabled = computed(
3030
() => ! enabling.value && usePage().props.value.user.two_factor_enabled,
3131
);
3232
33+
watch(twoFactorEnabled, () => {
34+
if (! twoFactorEnabled.value) {
35+
confirmationForm.reset();
36+
confirmationForm.clearErrors();
37+
}
38+
});
39+
3340
const enableTwoFactorAuthentication = () => {
3441
enabling.value = true;
3542
@@ -67,6 +74,7 @@ const showRecoveryCodes = () => {
6774
6875
const confirmTwoFactorAuthentication = () => {
6976
confirmationForm.post('/user/confirmed-two-factor-authentication', {
77+
errorBag: "confirmTwoFactorAuthentication",
7078
preserveScroll: true,
7179
preserveState: true,
7280
onSuccess: () => {
@@ -111,7 +119,7 @@ const disableTwoFactorAuthentication = () => {
111119
You have enabled two factor authentication.
112120
</h3>
113121

114-
<h3 v-else-if="confirming" class="text-lg font-medium text-gray-900">
122+
<h3 v-else-if="twoFactorEnabled && confirming" class="text-lg font-medium text-gray-900">
115123
Finish enabling two factor authentication.
116124
</h3>
117125

0 commit comments

Comments
 (0)