2.2.1 - Misc improvements and cleanup
All checks were successful
Docker Deploy / build-and-push (push) Successful in 4m3s
All checks were successful
Docker Deploy / build-and-push (push) Successful in 4m3s
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue';
|
||||
import { Icon } from '@iconify/vue';
|
||||
import { startAuthentication } from '@simplewebauthn/browser';
|
||||
import { ref } from "vue";
|
||||
import { Icon } from "@iconify/vue";
|
||||
import { startAuthentication } from "@simplewebauthn/browser";
|
||||
|
||||
const loading = ref(false);
|
||||
const error = ref<string | null>(null);
|
||||
@@ -11,45 +11,41 @@ async function handlePasskeyLogin() {
|
||||
error.value = null;
|
||||
|
||||
try {
|
||||
// 1. Get options from server
|
||||
const resp = await fetch('/api/auth/passkey/login/start');
|
||||
const resp = await fetch("/api/auth/passkey/login/start");
|
||||
|
||||
if (!resp.ok) {
|
||||
throw new Error('Failed to start passkey login');
|
||||
throw new Error("Failed to start passkey login");
|
||||
}
|
||||
|
||||
const options = await resp.json();
|
||||
|
||||
// 2. Browser handles interaction
|
||||
let asseResp;
|
||||
try {
|
||||
asseResp = await startAuthentication(options);
|
||||
asseResp = await startAuthentication({ optionsJSON: options });
|
||||
} catch (err) {
|
||||
if ((err as any).name === 'NotAllowedError') {
|
||||
// User cancelled or timed out
|
||||
if ((err as any).name === "NotAllowedError") {
|
||||
return;
|
||||
}
|
||||
console.error(err);
|
||||
error.value = 'Failed to authenticate with passkey';
|
||||
error.value = "Failed to authenticate with passkey";
|
||||
return;
|
||||
}
|
||||
|
||||
// 3. Verify with server
|
||||
const verificationResp = await fetch('/api/auth/passkey/login/finish', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
const verificationResp = await fetch("/api/auth/passkey/login/finish", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(asseResp),
|
||||
});
|
||||
|
||||
const verificationJSON = await verificationResp.json();
|
||||
if (verificationJSON.verified) {
|
||||
window.location.href = '/dashboard';
|
||||
window.location.href = "/dashboard";
|
||||
} else {
|
||||
error.value = 'Login failed. Please try again.';
|
||||
error.value = "Login failed. Please try again.";
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Error during passkey login:', err);
|
||||
error.value = 'An error occurred during login';
|
||||
console.error("Error during passkey login:", err);
|
||||
error.value = "An error occurred during login";
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user