Skip to content

Commit 9beb520

Browse files
committed
fix(core): prevent double-submit on login flow grant page
Add isSubmitting guard to onSubmit so the button is disabled and shows a loading spinner as soon as the first submit fires. A second click while the form is in-flight is dropped via event.preventDefault(). Fixes: #62327 Signed-off-by: okxint <cashmein.eth@gmail.com>
1 parent 4ad68f0 commit 9beb520

1 file changed

Lines changed: 27 additions & 6 deletions

File tree

‎core/src/views/LoginFlowGrant.vue‎

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
-->
55

66
<script setup lang="ts">
7+
import { ref } from 'vue'
78
import { getRequestToken } from '@nextcloud/auth'
89
import { loadState } from '@nextcloud/initial-state'
910
import { t } from '@nextcloud/l10n'
1011
import { confirmPassword, isPasswordConfirmationRequired, PwdConfirmationMode } from '@nextcloud/password-confirmation'
1112
import NcButton from '@nextcloud/vue/components/NcButton'
13+
import NcLoadingIcon from '@nextcloud/vue/components/NcLoadingIcon'
1214
import NcNoteCard from '@nextcloud/vue/components/NcNoteCard'
1315
import LoginFlowContainer from '../components/LoginFlow/LoginFlowContainer.vue'
1416
@@ -40,19 +42,31 @@ const {
4042
4143
const requestToken = getRequestToken()
4244
45+
const isSubmitting = ref(false)
46+
4347
/**
4448
* Handle submit event to confirm password if required
4549
*
4650
* @param event - The submit event
4751
*/
4852
async function onSubmit(event: SubmitEvent) {
49-
if (isPasswordConfirmationRequired(PwdConfirmationMode.Lax)) {
53+
if (isSubmitting.value) {
5054
event.preventDefault()
51-
event.stopPropagation()
55+
return
56+
}
57+
58+
isSubmitting.value = true
59+
try {
60+
if (isPasswordConfirmationRequired(PwdConfirmationMode.Lax)) {
61+
event.preventDefault()
62+
event.stopPropagation()
5263
53-
await confirmPassword()
54-
;(event.target as HTMLFormElement).submit()
55-
return false
64+
await confirmPassword()
65+
;(event.target as HTMLFormElement).submit()
66+
return
67+
}
68+
} finally {
69+
isSubmitting.value = false
5670
}
5771
}
5872
</script>
@@ -90,7 +104,14 @@ async function onSubmit(event: SubmitEvent) {
90104
name="providedRedirectUri"
91105
:value="providedRedirectUri">
92106

93-
<NcButton :class="$style.loginFlowGrant__button" type="submit" variant="primary">
107+
<NcButton
108+
:class="$style.loginFlowGrant__button"
109+
:disabled="isSubmitting"
110+
type="submit"
111+
variant="primary">
112+
<template v-if="isSubmitting" #icon>
113+
<NcLoadingIcon />
114+
</template>
94115
{{ t('core', 'Grant access') }}
95116
</NcButton>
96117
</form>

0 commit comments

Comments
 (0)