|
@@ -14,12 +14,17 @@ export const POST: APIRoute = async ({ request, params }) => {
|
|
|
await init();
|
|
await init();
|
|
|
|
|
|
|
|
const currentUser = getUserFromRequest(request);
|
|
const currentUser = getUserFromRequest(request);
|
|
|
|
|
+
|
|
|
|
|
+ console.log(request.headers.get("cookie"));
|
|
|
|
|
+ console.log(currentUser);
|
|
|
if (!currentUser) return json({ error: "Not authenticated" }, 401);
|
|
if (!currentUser) return json({ error: "Not authenticated" }, 401);
|
|
|
|
|
|
|
|
const game = await getGame(params.id!);
|
|
const game = await getGame(params.id!);
|
|
|
if (!game) return json({ error: "Not found" }, 404);
|
|
if (!game) return json({ error: "Not found" }, 404);
|
|
|
- if (game.status !== "waiting") return json({ error: "Game already started" }, 400);
|
|
|
|
|
- if (game.player1 === currentUser) return json({ error: "You are already player 1" }, 400);
|
|
|
|
|
|
|
+ if (game.status !== "waiting")
|
|
|
|
|
+ return json({ error: "Game already started" }, 400);
|
|
|
|
|
+ if (game.player1 === currentUser)
|
|
|
|
|
+ return json({ error: "You are already player 1" }, 400);
|
|
|
if (game.player2) return json({ error: "Game is full" }, 400);
|
|
if (game.player2) return json({ error: "Game is full" }, 400);
|
|
|
|
|
|
|
|
const updated = await updateGame(game.id, {
|
|
const updated = await updateGame(game.id, {
|