Skip to content

Commit

Permalink
fix ユーザのサインイン、アップ時にexperienceを作成させる
Browse files Browse the repository at this point in the history
  • Loading branch information
hikahana committed Nov 13, 2024
1 parent 02dd908 commit 926c295
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions app/src/lib/signInAndUp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 = "/";
};

0 comments on commit 926c295

Please sign in to comment.