From 9b918b1c6a141e6cc8de48a37dfc43bfef59e44c Mon Sep 17 00:00:00 2001 From: Daniel McCrystal Date: Sun, 24 Aug 2025 13:59:16 -0400 Subject: [PATCH] hotfix --- packages/client/src/app.tsx | 5 ++++- packages/client/src/profile.ts | 3 ++- packages/server/src/api.ts | 19 +++++++++++-------- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/packages/client/src/app.tsx b/packages/client/src/app.tsx index 8e0637b..dfeb824 100644 --- a/packages/client/src/app.tsx +++ b/packages/client/src/app.tsx @@ -6,10 +6,13 @@ import pkg from "../package.json"; import "./style.css"; import api from "./api"; import Cookies from "js-cookie"; +import { mePromise } from "./profile"; const Profile = () => { let dialogRef!: HTMLDialogElement; - const [profile] = createResource(async () => api.profile.get()); + const [profile] = createResource(() => + mePromise.then(() => api.profile.get()) + ); return ( <> diff --git a/packages/client/src/profile.ts b/packages/client/src/profile.ts index e2828ca..1af5b36 100644 --- a/packages/client/src/profile.ts +++ b/packages/client/src/profile.ts @@ -3,7 +3,8 @@ import { ApiType } from "./fn"; import api from "./api"; import hash from "object-hash"; -export const [me] = createResource(() => api.whoami.post().then((r) => r.data)); +export const mePromise = api.whoami.post().then((r) => r.data); +export const [me] = createResource(() => mePromise); const playerProfiles: { [humanKey: string]: Resource>; diff --git a/packages/server/src/api.ts b/packages/server/src/api.ts index 375b5b3..e09fe59 100644 --- a/packages/server/src/api.ts +++ b/packages/server/src/api.ts @@ -9,11 +9,19 @@ import { human } from "./human"; import dayjs from "dayjs"; import db from "./db"; import { liveTable, WsOut, WsIn } from "./table"; +import { Human } from "@prisma/client"; const api = new Elysia({ prefix: "/api" }) .post("/whoami", async ({ cookie: { token } }) => { - let human; - if (token.value == null) { + let human: Human | null; + if ( + token.value == null || + (human = await db.human.findUnique({ + where: { + token: token.value, + }, + })) == null + ) { human = await db.human.create({ data: {}, }); @@ -22,13 +30,8 @@ const api = new Elysia({ prefix: "/api" }) expires: dayjs().add(1, "year").toDate(), httpOnly: true, }); - } else { - human = await db.human.findUniqueOrThrow({ - where: { - token: token.value, - }, - }); } + return human.key; }) .use(human)