|
|
@@ -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;
|
|
|
}
|
|
|
|