From dc598a514620ddf03ea4066cc1384f411046e42a Mon Sep 17 00:00:00 2001 From: Karl Ludwig Weise Date: Thu, 11 Sep 2025 12:18:37 +0200 Subject: [PATCH] Autosubmit login form on adding passkey (#78) Co-authored-by: Karl Ludwig Weise --- src/lib/utils/passkey.ts | 23 +++++++++++++++------- src/routes/(pages)/login/login-form.svelte | 5 +++++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/lib/utils/passkey.ts b/src/lib/utils/passkey.ts index f838fcb..9815944 100644 --- a/src/lib/utils/passkey.ts +++ b/src/lib/utils/passkey.ts @@ -1,15 +1,24 @@ import logger from "$lib/logger"; export const arrayBufferToBase64 = (buffer: ArrayBuffer): string => { - const bytes = new Uint8Array(buffer); - let binary = ""; + try { + const bytes = new Uint8Array(buffer); + let binary = ""; - // Simple loop, no fancy operations - for (let i = 0; i < bytes.length; i++) { - binary += String.fromCharCode(bytes[i]); + // Simple loop, no fancy operations + for (let i = 0; i < bytes.length; i++) { + binary += String.fromCharCode(bytes[i]); + } + + return window.btoa(binary); + } catch (error) { + logger.error("Failed to convert ArrayBuffer to Base64", { + error, + notes: + "If you see this error locally, the best way to use passkeys is Chromium as of writing this", + }); + throw error; } - - return window.btoa(binary); }; export const base64UrlToArrayBuffer = (base64url: string) => { diff --git a/src/routes/(pages)/login/login-form.svelte b/src/routes/(pages)/login/login-form.svelte index 90f1471..b1f6c05 100644 --- a/src/routes/(pages)/login/login-form.svelte +++ b/src/routes/(pages)/login/login-form.svelte @@ -120,6 +120,11 @@ // Update UI to show passkey is ready $passkeyLoading = "success"; + + const isValid = await form.validateForm(); + if (isValid) { + form.submit(); + } } };