mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 10:31:15 +00:00
fix(editor): Allow password managers to autocomplete MFA code during login (#18865)
This commit is contained in:
@@ -95,5 +95,6 @@ export type InputAutocompletePropType =
|
|||||||
| 'current-password'
|
| 'current-password'
|
||||||
| 'given-name'
|
| 'given-name'
|
||||||
| 'family-name'
|
| 'family-name'
|
||||||
|
| 'one-time-code'
|
||||||
| 'email'; // https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete
|
| 'email'; // https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete
|
||||||
export type ElementPlusSizePropType = '' | 'small' | 'large' | 'default' | undefined;
|
export type ElementPlusSizePropType = '' | 'small' | 'large' | 'default' | undefined;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type { IFormInputs } from '@/Interface';
|
import type { IFormInputs, InputAutocompletePropType } from '@/Interface';
|
||||||
import Logo from '@/components/Logo/Logo.vue';
|
import Logo from '@/components/Logo/Logo.vue';
|
||||||
import {
|
import {
|
||||||
MFA_AUTHENTICATION_RECOVERY_CODE_INPUT_MAX_LENGTH,
|
MFA_AUTHENTICATION_RECOVERY_CODE_INPUT_MAX_LENGTH,
|
||||||
@@ -33,6 +33,7 @@ const showRecoveryCodeForm = ref(false);
|
|||||||
const verifyingMfaCode = ref(false);
|
const verifyingMfaCode = ref(false);
|
||||||
const formError = ref('');
|
const formError = ref('');
|
||||||
const { reportError } = toRefs(props);
|
const { reportError } = toRefs(props);
|
||||||
|
const mfaFormRef = ref<{ $el?: HTMLElement } | null>(null);
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// #region Composable
|
// #region Composable
|
||||||
@@ -64,6 +65,7 @@ const formField = (
|
|||||||
placeholder: string,
|
placeholder: string,
|
||||||
maxlength: number,
|
maxlength: number,
|
||||||
focus = true,
|
focus = true,
|
||||||
|
autocomplete: InputAutocompletePropType = 'off',
|
||||||
) => {
|
) => {
|
||||||
return {
|
return {
|
||||||
name,
|
name,
|
||||||
@@ -75,6 +77,7 @@ const formField = (
|
|||||||
capitalize: true,
|
capitalize: true,
|
||||||
validateOnBlur: false,
|
validateOnBlur: false,
|
||||||
focusInitially: focus,
|
focusInitially: focus,
|
||||||
|
autocomplete,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -97,6 +100,7 @@ const onBackClick = () => {
|
|||||||
hasAnyChanges.value = true;
|
hasAnyChanges.value = true;
|
||||||
formInputs.value = [mfaCodeFieldWithDefaults()];
|
formInputs.value = [mfaCodeFieldWithDefaults()];
|
||||||
emit('onBackClick', MFA_FORM.MFA_RECOVERY_CODE);
|
emit('onBackClick', MFA_FORM.MFA_RECOVERY_CODE);
|
||||||
|
focusMfaCodeAfterPasswordManager();
|
||||||
};
|
};
|
||||||
|
|
||||||
const onSubmit = (formData: unknown) => {
|
const onSubmit = (formData: unknown) => {
|
||||||
@@ -108,6 +112,19 @@ const onSubmit = (formData: unknown) => {
|
|||||||
emit('submit', data);
|
emit('submit', data);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const focusMfaCodeAfterPasswordManager = () => {
|
||||||
|
setTimeout(() => {
|
||||||
|
if (mfaFormRef.value) {
|
||||||
|
const container = mfaFormRef.value.$el;
|
||||||
|
if (!container) return;
|
||||||
|
const inputElement = container.querySelector('input[name="mfaCode"]') as HTMLInputElement;
|
||||||
|
if (inputElement) {
|
||||||
|
inputElement.focus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 200);
|
||||||
|
};
|
||||||
|
|
||||||
const onInput = ({ target: { value, name } }: { target: { value: string; name: string } }) => {
|
const onInput = ({ target: { value, name } }: { target: { value: string; name: string } }) => {
|
||||||
const isSubmittingMfaCode = name === 'mfaCode';
|
const isSubmittingMfaCode = name === 'mfaCode';
|
||||||
const inputValidLength = isSubmittingMfaCode
|
const inputValidLength = isSubmittingMfaCode
|
||||||
@@ -149,6 +166,8 @@ const mfaCodeFieldWithDefaults = () => {
|
|||||||
i18.baseText('mfa.code.input.label'),
|
i18.baseText('mfa.code.input.label'),
|
||||||
i18.baseText('mfa.code.input.placeholder'),
|
i18.baseText('mfa.code.input.placeholder'),
|
||||||
MFA_AUTHENTICATION_CODE_INPUT_MAX_LENGTH,
|
MFA_AUTHENTICATION_CODE_INPUT_MAX_LENGTH,
|
||||||
|
false,
|
||||||
|
'one-time-code',
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -168,6 +187,8 @@ const {
|
|||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
formInputs.value = [mfaCodeFieldWithDefaults()];
|
formInputs.value = [mfaCodeFieldWithDefaults()];
|
||||||
|
|
||||||
|
focusMfaCodeAfterPasswordManager();
|
||||||
});
|
});
|
||||||
|
|
||||||
// #endregion
|
// #endregion
|
||||||
@@ -190,6 +211,7 @@ onMounted(() => {
|
|||||||
data-test-id="mfa-login-form"
|
data-test-id="mfa-login-form"
|
||||||
:inputs="formInputs"
|
:inputs="formInputs"
|
||||||
:event-bus="formBus"
|
:event-bus="formBus"
|
||||||
|
ref="mfaFormRef"
|
||||||
@input="onInput"
|
@input="onInput"
|
||||||
@submit="onSubmit"
|
@submit="onSubmit"
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user