""auth"" working nicely
This commit is contained in:
@@ -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())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user