diff options
Diffstat (limited to 'fe/src/lib/LoginForm.svelte')
-rw-r--r-- | fe/src/lib/LoginForm.svelte | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/fe/src/lib/LoginForm.svelte b/fe/src/lib/LoginForm.svelte index 22c0faf..499a457 100644 --- a/fe/src/lib/LoginForm.svelte +++ b/fe/src/lib/LoginForm.svelte | |||
@@ -1,8 +1,8 @@ | |||
1 | <script lang='ts'> | 1 | <script lang='ts'> |
2 | import { token } from '../stores/auth'; | 2 | import { token, user, preferences } from '../stores/auth'; |
3 | import Card from './Card.svelte'; | 3 | import Card from './Card.svelte'; |
4 | 4 | ||
5 | let user = { | 5 | let credentials: CredentialObject = { |
6 | username: '', | 6 | username: '', |
7 | password: '' | 7 | password: '' |
8 | } | 8 | } |
@@ -19,11 +19,11 @@ function prepareCredentials ({ username, password }: CredentialObject): string { | |||
19 | } | 19 | } |
20 | 20 | ||
21 | async function onSubmit (e) { | 21 | async function onSubmit (e) { |
22 | if (!user.username || !user.password) { | 22 | if (!credentials.username || !credentials.password) { |
23 | error = 'please enter your username and password'; | 23 | error = 'please enter your username and password'; |
24 | return; | 24 | return; |
25 | } | 25 | } |
26 | const auth = prepareCredentials(user); | 26 | const auth = prepareCredentials(credentials); |
27 | 27 | ||
28 | const response = await fetch('http://localhost:8080/api/v1/auth', { | 28 | const response = await fetch('http://localhost:8080/api/v1/auth', { |
29 | method: 'POST', | 29 | method: 'POST', |
@@ -38,7 +38,9 @@ async function onSubmit (e) { | |||
38 | } | 38 | } |
39 | 39 | ||
40 | if (response.ok) { | 40 | if (response.ok) { |
41 | const { token: apiToken } = await response.json(); | 41 | const { token: apiToken, user: userData, preferences: userPreferences } = await response.json(); |
42 | user.setUser(userData); | ||
43 | preferences.set(userPreferences); | ||
42 | token.authenticate(apiToken); | 44 | token.authenticate(apiToken); |
43 | } | 45 | } |
44 | 46 | ||
@@ -50,11 +52,11 @@ async function onSubmit (e) { | |||
50 | <form class="form" on:submit|preventDefault={onSubmit}> | 52 | <form class="form" on:submit|preventDefault={onSubmit}> |
51 | <div class='form input group'> | 53 | <div class='form input group'> |
52 | <label for="username">Username</label> | 54 | <label for="username">Username</label> |
53 | <input bind:value={user.username} id="username" name='username' type="text" autocomplete="username" /> | 55 | <input bind:value={credentials.username} id="username" name='username' type="text" autocomplete="username" /> |
54 | </div> | 56 | </div> |
55 | <div class='form input group'> | 57 | <div class='form input group'> |
56 | <label for="password">Password</label> | 58 | <label for="password">Password</label> |
57 | <input bind:value={user.password} id="password" name='password' type="password" autocomplete="current-password"/> | 59 | <input bind:value={credentials.password} id="password" name='password' type="password" autocomplete="current-password"/> |
58 | </div> | 60 | </div> |
59 | {#if error} | 61 | {#if error} |
60 | <p class="error">{error}</p> | 62 | <p class="error">{error}</p> |