planetwars.dev/web/pw-server/src/routes/register.svelte

39 lines
905 B
Svelte
Raw Normal View History

2021-12-30 16:34:50 +01:00
<script lang="ts">
2021-12-31 11:38:06 +01:00
let username: string | undefined;
let password: string | undefined;
2021-12-30 16:34:50 +01:00
2021-12-31 11:38:06 +01:00
const onSubmit = () => {
if (username === undefined || username.trim() === "") {
return;
}
2021-12-30 16:34:50 +01:00
2021-12-31 11:38:06 +01:00
if (password === undefined || password.trim() === "") {
2021-12-30 16:34:50 +01:00
return;
}
2021-12-31 11:38:06 +01:00
fetch("/api/register", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
username,
password,
}),
})
.then((resp) => resp.json())
.then((data) => {
console.log(data);
});
};
2021-12-30 16:34:50 +01:00
</script>
<h1>Register</h1>
<form on:submit|preventDefault={onSubmit}>
2021-12-31 11:38:06 +01:00
<label for="username">Username</label>
<input name="username" bind:value={username} />
<label for="password">Password</label>
<input type="password" name="password" bind:value={password} />
<button type="submit">Register</button>
2021-12-30 16:34:50 +01:00
</form>