From 9f9a33cbf55d38987a66b709284d2bb4ffea0fe9 Mon Sep 17 00:00:00 2001
From: Doog <157747121+doogongithub@users.noreply.github.com>
Date: Thu, 29 Feb 2024 20:13:48 -0500
Subject: modify api, build additional FE components, add types

---
 fe/src/lib/LoginForm.svelte | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

(limited to 'fe/src/lib/LoginForm.svelte')

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 @@
 <script lang='ts'>
-import { token } from '../stores/auth';
+import { token, user, preferences } from '../stores/auth';
 import Card from './Card.svelte';
 
-let user = {
+let credentials: CredentialObject = {
     username: '',
     password: ''
 }
@@ -19,11 +19,11 @@ function prepareCredentials ({ username, password }: CredentialObject): string {
 }
 
 async function onSubmit (e) {
-    if (!user.username || !user.password) {
+    if (!credentials.username || !credentials.password) {
         error = 'please enter your username and password';
         return;
     }
-   const auth = prepareCredentials(user);
+   const auth = prepareCredentials(credentials);
 
    const response = await fetch('http://localhost:8080/api/v1/auth', {
         method: 'POST',
@@ -38,7 +38,9 @@ async function onSubmit (e) {
     }
 
     if (response.ok) {
-        const { token: apiToken } = await response.json();
+        const { token: apiToken, user: userData, preferences: userPreferences } = await response.json();
+        user.setUser(userData);
+        preferences.set(userPreferences);
         token.authenticate(apiToken);
     }
 
@@ -50,11 +52,11 @@ async function onSubmit (e) {
     <form class="form" on:submit|preventDefault={onSubmit}>
         <div class='form input group'>
             <label for="username">Username</label>
-            <input bind:value={user.username} id="username" name='username' type="text" autocomplete="username" />
+            <input bind:value={credentials.username} id="username" name='username' type="text" autocomplete="username" />
         </div>
         <div class='form input group'>
             <label for="password">Password</label>
-            <input bind:value={user.password} id="password" name='password' type="password" autocomplete="current-password"/>
+            <input bind:value={credentials.password} id="password" name='password' type="password" autocomplete="current-password"/>
         </div>
         {#if error}
             <p class="error">{error}</p>
-- 
cgit v1.1

