some proper auth
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user