فهرست منبع

Refactor the refactor

Lee Morgan 3 هفته پیش
والد
کامیت
9f796f6547
1فایلهای تغییر یافته به همراه13 افزوده شده و 2 حذف شده
  1. 13 2
      src/routes/(app)/game/new/+page.svelte

+ 13 - 2
src/routes/(app)/game/new/+page.svelte

@@ -21,11 +21,16 @@
     const submit = async (e) => {
         e.preventDefault();
 
+        const gameBody = {
+            title: title,
+            game_context: gameContext
+        };
+
         const gameRes = await fetch(`${PUBLIC_API_URL}/game`, {
             method: "POST",
             headers: {"Content-Type": "application/json"},
             credentials: "include",
-            body: JSON.stringify({ title, game_context: gameContext })
+            body: JSON.stringify(gameBody)
         });
 
         const gameData = await gameRes.json();
@@ -35,16 +40,22 @@
             return;
         }
 
+        let characterBody = {
+            name: characterName,
+            description: characterDescription
+        };
+
         const charRes = await fetch(`${PUBLIC_API_URL}/game/${gameData.id}/character`, {
             method: "POST",
             headers: {"Content-Type": "application/json"},
             credentials: "include",
-            body: JSON.stringify({ name: characterName, description: characterDescription })
+            body: JSON.stringify(characterBody)
         });
 
         const charData = await charRes.json();
         if (!charRes.ok) {
             toast(charData.error.message, "error");
+            if(charRes.status === 401) goto("/");
             return;
         }