From 926c295d7cb61a1f230584e724b62afe03d94898 Mon Sep 17 00:00:00 2001 From: hikahana <22.h.hanada.nutfes@gmail.com> Date: Wed, 13 Nov 2024 08:23:26 +0000 Subject: [PATCH] =?UTF-8?q?fix=20=E3=83=A6=E3=83=BC=E3=82=B6=E3=81=AE?= =?UTF-8?q?=E3=82=B5=E3=82=A4=E3=83=B3=E3=82=A4=E3=83=B3=E3=80=81=E3=82=A2?= =?UTF-8?q?=E3=83=83=E3=83=97=E6=99=82=E3=81=ABexperience=E3=82=92?= =?UTF-8?q?=E4=BD=9C=E6=88=90=E3=81=95=E3=81=9B=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/lib/signInAndUp.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/app/src/lib/signInAndUp.ts b/app/src/lib/signInAndUp.ts index 89ec934..5663015 100644 --- a/app/src/lib/signInAndUp.ts +++ b/app/src/lib/signInAndUp.ts @@ -23,6 +23,10 @@ export const signInOrUp = async (firebaseUser: FirebaseUser) => { if (res.status === 200) { storeStorageUser(user); + const userData = await res.json(); + if (!userData.experiencePoint) { + await createExp(userData.id); + } toRoot(); } else { await signUp(user); @@ -53,6 +57,26 @@ const signUp = async (user: User) => { } }; +const createExp = async (userId: number) => { + try { + const res = await fetch("/api/experiencePoint/new", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(userId), + }); + + if (res.status === 200) { + toRoot(); + } else { + throw new Error("作成に失敗しました"); + } + } catch (error) { + console.error("エラーが発生しました:", error); + } +}; + const toRoot = () => { window.location.href = "/"; };