|
|
@@ -40,20 +40,32 @@
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- let characterBody = {
|
|
|
- name: characterName,
|
|
|
- description: characterDescription
|
|
|
- };
|
|
|
+ const sessionProm = fetch(`${PUBLIC_API_URL}/game/${gameData.id}/session`, {
|
|
|
+ method: "POST",
|
|
|
+ headers: {"Content-Type": "application/json"},
|
|
|
+ credentials: "include"
|
|
|
+ });
|
|
|
|
|
|
- const charRes = await fetch(`${PUBLIC_API_URL}/game/${gameData.id}/character`, {
|
|
|
+ const charProm = fetch(`${PUBLIC_API_URL}/game/${gameData.id}/character`, {
|
|
|
method: "POST",
|
|
|
headers: {"Content-Type": "application/json"},
|
|
|
credentials: "include",
|
|
|
- body: JSON.stringify(characterBody)
|
|
|
+ body: JSON.stringify({
|
|
|
+ name: characterName,
|
|
|
+ description: characterDescription
|
|
|
+ })
|
|
|
});
|
|
|
|
|
|
- const charData = await charRes.json();
|
|
|
- if (!charRes.ok) {
|
|
|
+ const [sessionRes, charRes] = await Promise.all([sessionProm, charProm]);
|
|
|
+ const [sessionData, charData] = await Promise.all([sessionRes.json(), charRes.json()]);
|
|
|
+
|
|
|
+ if(!sessionRes.ok){
|
|
|
+ toast(sessionData.error.message, "error");
|
|
|
+ if(sessionRes.status === 401) goto("/");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!charRes.ok){
|
|
|
toast(charData.error.message, "error");
|
|
|
if(charRes.status === 401) goto("/");
|
|
|
return;
|