tokens fr

This commit is contained in:
2025-08-18 17:47:39 -04:00
parent 601e3660d3
commit 3f1635880a
11 changed files with 204 additions and 106 deletions

View File

@@ -1,16 +1,20 @@
import { prisma } from "./db/db";
import { Elysia, t } from "elysia";
import { Prisma } from "@prisma/client";
import { simpleApi } from "./games/simple";
import { human } from "./human";
import dayjs from "dayjs";
import db from "./db";
const api = new Elysia({ prefix: "/api" })
.post("/whoami", async ({ cookie: { token } }) => {
if (token.value == null) {
const newHuman = await prisma.human.create({
const newHuman = await db.human.create({
data: {},
});
token.value = newHuman.key;
token.set({
value: newHuman.token,
expires: dayjs().add(1, "year").toDate(),
httpOnly: true,
});
}
return token.value;
})
@@ -18,7 +22,7 @@ const api = new Elysia({ prefix: "/api" })
.post(
"/setName",
({ body: { name }, humanKey }) =>
prisma.human.update({
db.human.update({
where: {
key: humanKey,
},
@@ -33,16 +37,21 @@ const api = new Elysia({ prefix: "/api" })
}
)
.get("/profile", ({ humanKey }) =>
prisma.human.findFirst({ where: { key: humanKey } })
db.human.findFirst({ where: { key: humanKey } })
)
.get("/games", () => prisma.game.findMany())
.get("/games", () => [{ key: "simple", name: "simple" }])
.get("/instances", ({ query: { game } }) =>
prisma.instance.findMany({
.get("/instances", ({ query: { game }, humanKey }) =>
db.instance.findMany({
where: {
game: {
name: game,
},
players: {
some: {
key: humanKey,
},
},
},
select: {
id: true,