|
@@ -1,6 +1,6 @@
|
|
|
import type { APIRoute } from "astro";
|
|
import type { APIRoute } from "astro";
|
|
|
import { init, createGame, getRecentGames, json } from "@utils/db";
|
|
import { init, createGame, getRecentGames, json } from "@utils/db";
|
|
|
-import { getUserFromRequest } from "@utils/auth";
|
|
|
|
|
|
|
+import { getUserFromRequest, checkOrigin } from "@utils/auth";
|
|
|
|
|
|
|
|
export const GET: APIRoute = async () => {
|
|
export const GET: APIRoute = async () => {
|
|
|
await init();
|
|
await init();
|
|
@@ -9,13 +9,11 @@ export const GET: APIRoute = async () => {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
export const POST: APIRoute = async ({ request }) => {
|
|
export const POST: APIRoute = async ({ request }) => {
|
|
|
|
|
+ const blocked = checkOrigin(request);
|
|
|
|
|
+ if (blocked) return blocked;
|
|
|
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 id = crypto.randomUUID().replace(/-/g, "").slice(0, 12);
|
|
const id = crypto.randomUUID().replace(/-/g, "").slice(0, 12);
|