""auth"" working nicely

This commit is contained in:
2025-08-17 19:32:01 -04:00
parent c755b83d3d
commit ef5a5e059a
5 changed files with 44 additions and 42 deletions

View File

@@ -2,24 +2,24 @@ import { prisma } from "./db/db";
import { Elysia, t } from "elysia";
import { Prisma } from "@prisma/client";
import { simpleApi } from "./games/simple";
import { human } from "./human";
const api = new Elysia({ prefix: "/api" })
.onBeforeHandle(async ({ cookie: { token } }) => {
.post("/whoami", 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() }) })
.use(human)
.post(
"/setName",
({ cookie: { token: humanKey }, body: { name } }) =>
({ body: { name }, humanKey }) =>
prisma.human.update({
where: {
key: humanKey.value,
key: humanKey,
},
data: {
name,
@@ -31,8 +31,8 @@ const api = new Elysia({ prefix: "/api" })
}),
}
)
.get("/profile", ({ cookie: { token: humanKey } }) =>
prisma.human.findFirst({ where: { key: humanKey.value } })
.get("/profile", ({ humanKey }) =>
prisma.human.findFirst({ where: { key: humanKey } })
)
.get("/games", () => prisma.game.findMany())