Skip to content

Commit

Permalink
Merge branch 'totp-autofocus' into 'main'
Browse files Browse the repository at this point in the history
Autofocus OTP input in login form

See merge request reportcreator/reportcreator!735
  • Loading branch information
MWedl committed Oct 23, 2024
2 parents 676fb52 + df69687 commit 884fb7f
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions frontend/src/components/LoginForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
</template>
<template v-else-if="currentMfaMethod!.method_type === MfaMethodType.TOTP">
<v-otp-input
ref="otpRef"
v-model="formCode.code"
type="number"
length="6"
Expand All @@ -71,6 +72,7 @@
</template>
<template v-else-if="currentMfaMethod!.method_type === MfaMethodType.BACKUP">
<v-otp-input
ref="otpRef"
v-model="formCode.code"
type="text"
length="12"
Expand Down Expand Up @@ -128,6 +130,7 @@

<script setup lang="ts">
import { get as navigatorCredentialsGet, parseRequestOptionsFromJSON } from "@github/webauthn-json/browser-ponyfill";
import type { VOtpInput } from "vuetify/components";
import { LoginResponseStatus, mfaMethodChoices, MfaMethodType } from '#imports';
const props = defineProps({
Expand Down Expand Up @@ -157,6 +160,7 @@ const currentMfaMethod = ref<MfaMethod | null>(null);
const formCode = ref({
code: '',
});
const otpRef = ref<VOtpInput|null>(null);
async function loginStep(fn: () => Promise<LoginResponse|null>) {
if (actionInProgress.value) {
Expand Down Expand Up @@ -212,12 +216,17 @@ async function beginMfaLogin(mfaMethod: MfaMethod) {
formCode.value = { code: '' };
if (currentMfaMethod.value.method_type === MfaMethodType.FIDO2) {
// Start FIDO2 flow
await nextTick();
await loginStep(async () => {
const options = await $fetch<any>('/api/v1/auth/login/fido2/begin/', { method: 'POST', body: {} });
const fido2Response = await navigatorCredentialsGet(parseRequestOptionsFromJSON(options));
return await $fetch('/api/v1/auth/login/fido2/complete/', { method: 'POST', body: fido2Response });
});
} else {
// Autofocus OTP input
await nextTick();
otpRef.value?.focus();
}
}
Expand Down

0 comments on commit 884fb7f

Please sign in to comment.