diff --git a/src/routes/login/+page.svelte b/src/routes/login/+page.svelte index 86527e3..e0d8f9b 100644 --- a/src/routes/login/+page.svelte +++ b/src/routes/login/+page.svelte @@ -15,13 +15,21 @@ const handleLogin = async () => { try { + // Check if email is a valid email address + const isValidEmail = /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email); + + // If it's not a valid email, rename it to 'username' + const loginData = isValidEmail ? { email } : { username: email }; + + // Make the fetch request with either 'email' or 'username' const response = await fetch(ACCOUNTS_WORKER_URL + '/login', { method: 'POST', - body: JSON.stringify({ email, password }), + body: JSON.stringify({ ...loginData, password }), headers: { 'Content-Type': 'application/json' } }); + const data = await response.json(); if (data.sessionKey) { // Set session key as a cookie @@ -51,7 +59,7 @@ {/if}