aboutsummaryrefslogtreecommitdiff
path: root/web/pw-server/src/routes/login.svelte
blob: 4a4fb564a301c11b397e4dd8f21caeafcf70134a (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
39
40
41
42
43
44
45
46
47
<script lang="ts">
  import * as auth from "$lib/auth";
  import { goto } from "$app/navigation";

  let username: string | undefined;
  let password: string | undefined;

  let error: string | undefined;

  async function submitLogin() {
    try {
      error = undefined;
      await auth.login({ username, password });
      goto("/");
    } catch (e) {
      error = e.message;
    }
  }

  function loggedIn(): boolean {
    let session = auth.get_session_token();
    return session !== null && session !== undefined;
  }
</script>

<div class="page-card">
  <div class="page-card-content">
    <h1 class="page-card-header">Sign in</h1>
    {#if error}
      <div class="error-message">{error}</div>
    {/if}
    <form class="account-form" on:submit|preventDefault={submitLogin}>
      <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">Submit</button>
    </form>
  </div>
</div>

<style lang="scss">
  @import "src/styles/account_forms.scss";
  .error-message {
    color: red;
  }
</style>