mirror of
https://github.com/JonasunderscoreJones/dash.jonasjones.dev.git
synced 2025-10-22 21:29:19 +02:00
added support for username in login
This commit is contained in:
parent
9bcaae01dd
commit
880a504eff
1 changed files with 10 additions and 2 deletions
|
@ -15,13 +15,21 @@
|
||||||
|
|
||||||
const handleLogin = async () => {
|
const handleLogin = async () => {
|
||||||
try {
|
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', {
|
const response = await fetch(ACCOUNTS_WORKER_URL + '/login', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({ email, password }),
|
body: JSON.stringify({ ...loginData, password }),
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
if (data.sessionKey) {
|
if (data.sessionKey) {
|
||||||
// Set session key as a cookie
|
// Set session key as a cookie
|
||||||
|
@ -51,7 +59,7 @@
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<form on:submit|preventDefault={handleLogin}>
|
<form on:submit|preventDefault={handleLogin}>
|
||||||
<label for="email">Email:</label>
|
<label for="email">Email or Username:</label>
|
||||||
<input id="email" bind:value={email} required />
|
<input id="email" bind:value={email} required />
|
||||||
|
|
||||||
<label for="password">Password:</label>
|
<label for="password">Password:</label>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue