Skip to content
Open
18 changes: 17 additions & 1 deletion custom/TwoFactorsPasskeysSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,23 @@
return JSON.stringify((credential as PublicKeyCredential).toJSON());
} catch (error) {
console.error(t('Error creating WebAuthn credential:', error));
adminforth.alert({ message: t('Error creating passkey.'), variant: 'warning' });

let message = t('Failed to create passkey.');

if (error?.name === 'InvalidStateError') {
message = t('A passkey for this account already exists on this device.');
}

if (error?.name === 'NotAllowedError') {
message = t('Passkey creation was cancelled.');
Comment thread
kulikp1 marked this conversation as resolved.
}

if (error?.name === 'NotSupportedError') {
message = t('Passkeys are not supported on this device or browser.');
}

adminforth.alert({ message, variant: 'danger'});

return null;
}
}
Expand Down
2 changes: 1 addition & 1 deletion custom/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
codeError.value = t('A previous passkey attempt was still pending. Please try again.');
return null;
} else if (name === 'NotAllowedError') {
adminforth.alert({ message: `The operation either timed out or was not allowed`, variant: 'warning' });
adminforth.alert({ message: `The operation either timed out or was not allowed`, variant: 'danger' });
codeError.value = 'The operation either timed out or was not allowed.';
return null;
} else {
Expand Down
3 changes: 2 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,8 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
this.adminforth.auth.setAuthCookie({expireInDuration: decoded.sessionDuration, response, username:decoded.userName, pk:decoded.pk})
return { status: 'ok', allowedLogin: true }
} else {
return {error: 'Verification failed'}
response.setStatus(403);
return {error: 'Wrong or expired TOTP code', }
}
}
}
Expand Down