summaryrefslogtreecommitdiff
path: root/ui/routes/(app)/me/+page.svelte
blob: ab214e977614611cba61c832d13356583a17d0b6 (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
<script>
  import LogOut from '$lib/components/LogOut.svelte';
  import Invites from '$lib/components/Invites.svelte';
  import ChangePassword from '$lib/components/ChangePassword.svelte';

  import { goto } from '$app/navigation';
  import * as api from '$lib/apiServer.js';
  import { currentUser } from '$lib/store';

  let invites = $state([]);

  async function logOut() {
    const response = await api.logOut();
    if (200 <= response.status && response.status < 300) {
      currentUser.set(null);
      await goto('/login');
    }
  }

  async function changePassword(currentPassword, newPassword) {
    await api.changePassword(currentPassword, newPassword);
  }

  async function createInvite() {
    let response = await api.createInvite();
    if (response.status === 200) {
      invites.push(response.data);
    }
  }
</script>

<ChangePassword {changePassword} />
<hr />
<Invites {invites} {createInvite} />
<hr />
<LogOut {logOut} />