소스 검색

Add login functionality

Lee Morgan 3 주 전
부모
커밋
0fa255a832
1개의 변경된 파일21개의 추가작업 그리고 2개의 파일을 삭제
  1. 21 2
      src/routes/login/+page.svelte

+ 21 - 2
src/routes/login/+page.svelte

@@ -1,12 +1,31 @@
 <script>
-    import "$lib/global.css";
     import favicon from "$lib/assets/favicon.png";
+    import {toast} from "$lib/toast.svelte.js";
+    import {PUBLIC_API_URL} from "$env/static/public";
+    import {goto} from "$app/navigation";
 
     let email = $state("");
     let password = $state("");
 
     const submit = async ()=>{
-        console.log("submit");
+        const body = {
+            email: email,
+            password: password
+        };
+
+        const response = await fetch(`${PUBLIC_API_URL}/user/login`, {
+            method: "POST",
+            headers: {"Content-Type": "application/json"},
+            credentials: "include",
+            body: JSON.stringify(body)
+        });
+
+        const responseBody = await response.json();
+        if(!response.ok){
+            toast(responseBody.error.message, "error");
+        }else{
+            goto("/dashboard");
+        }
     }
 </script>