diff options
author | Ilion Beyst <ilion.beyst@gmail.com> | 2022-01-04 23:24:31 +0100 |
---|---|---|
committer | Ilion Beyst <ilion.beyst@gmail.com> | 2022-01-04 23:24:31 +0100 |
commit | 9ccea2ea174f12f260f35ee01c9880d4b6591cf3 (patch) | |
tree | 5cd16e9bad158605aa735ff9d7f1e893364a68f2 /web | |
parent | 32131da67894b8bed5cf313b63a115b58ff23761 (diff) | |
download | planetwars.dev-9ccea2ea174f12f260f35ee01c9880d4b6591cf3.tar.xz planetwars.dev-9ccea2ea174f12f260f35ee01c9880d4b6591cf3.zip |
return user from login call
Diffstat (limited to 'web')
-rw-r--r-- | web/pw-server/src/routes/login.svelte | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/web/pw-server/src/routes/login.svelte b/web/pw-server/src/routes/login.svelte index 09b1834..da3fc83 100644 --- a/web/pw-server/src/routes/login.svelte +++ b/web/pw-server/src/routes/login.svelte @@ -5,8 +5,8 @@ let username: string | undefined; let password: string | undefined; - const onSubmit = () => { - fetch("/api/login", { + async function login() { + let response = await fetch("/api/login", { method: "POST", headers: { "Content-Type": "application/json", @@ -15,21 +15,23 @@ username, password, }), - }) - .then((response) => { - if (!response.ok) { - throw Error(response.statusText); - } - return response.text(); - }) - .then((token) => { - set_session_token(token); - goto("/"); - }); - }; + }); + + if (!response.ok) { + throw Error(response.statusText); + } + + let token = response.headers.get("Token"); + set_session_token(token); + + let user = await response.json(); + + goto("/"); + } function loggedIn(): boolean { - return get_session_token() != null; + let session = get_session_token(); + return session !== null && session !== undefined; } </script> @@ -37,7 +39,7 @@ you are logged in {/if} -<form on:submit|preventDefault={onSubmit}> +<form on:submit|preventDefault={login}> <label for="username">Username</label> <input name="username" bind:value={username} /> <label for="password">Password</label> |