some proper auth

This commit is contained in:
2025-08-15 15:27:24 -05:00
parent 4419dd7acc
commit 1c915d1713
9 changed files with 117 additions and 49 deletions

View File

@@ -4,19 +4,33 @@ import { Prisma } from "@prisma/client";
import { simpleApi } from "./games/simple";
const api = new Elysia({ prefix: "/api" })
// [wip]
.group("/prisma", (app) =>
app
.post("/game", ({ body }: { body: Prisma.GameFindManyArgs }) =>
prisma.game.findMany(body)
)
.post(
"/instance",
({ body }: { body: Prisma.InstanceFindManyArgs }) =>
prisma.instance.findMany(body)
)
.onBeforeHandle(async ({ cookie: { token } }) => {
if (token.value == null) {
console.log("CREATING NEW USER");
const newHuman = await prisma.human.create({
data: {},
});
token.value = newHuman.key;
}
})
.guard({ cookie: t.Object({ token: t.String() }) })
.post(
"/setName",
({ cookie: { token: humanKey }, body: { name } }) =>
prisma.human.update({
where: {
key: humanKey.value,
},
data: {
name,
},
}),
{
body: t.Object({
name: t.String(),
}),
}
)
.get("/games", () => prisma.game.findMany())
.get("/instances", ({ query: { game } }) =>
@@ -31,6 +45,7 @@ const api = new Elysia({ prefix: "/api" })
},
})
)
.use(simpleApi);
export default api;