aboutsummaryrefslogtreecommitdiff
path: root/web/pw-server/src/routes/register.svelte
blob: 6344399445c512410a5e38612bb9669751877bda (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<script lang="ts">
  let username: string | undefined;
  let password: string | undefined;

  const onSubmit = () => {
    if (username === undefined || username.trim() === "") {
      return;
    }

    if (password === undefined || password.trim() === "") {
      return;
    }

    fetch("/api/register", {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        username,
        password,
      }),
    })
      .then((resp) => resp.json())
      .then((data) => {
        console.log(data);
      });
  };
</script>

<h1>Register</h1>
<form on:submit|preventDefault={onSubmit}>
  <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>
</form>