hotfix
This commit is contained in:
@@ -6,10 +6,13 @@ import pkg from "../package.json";
|
|||||||
import "./style.css";
|
import "./style.css";
|
||||||
import api from "./api";
|
import api from "./api";
|
||||||
import Cookies from "js-cookie";
|
import Cookies from "js-cookie";
|
||||||
|
import { mePromise } from "./profile";
|
||||||
|
|
||||||
const Profile = () => {
|
const Profile = () => {
|
||||||
let dialogRef!: HTMLDialogElement;
|
let dialogRef!: HTMLDialogElement;
|
||||||
const [profile] = createResource(async () => api.profile.get());
|
const [profile] = createResource(() =>
|
||||||
|
mePromise.then(() => api.profile.get())
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ import { ApiType } from "./fn";
|
|||||||
import api from "./api";
|
import api from "./api";
|
||||||
import hash from "object-hash";
|
import hash from "object-hash";
|
||||||
|
|
||||||
export const [me] = createResource(() => api.whoami.post().then((r) => r.data));
|
export const mePromise = api.whoami.post().then((r) => r.data);
|
||||||
|
export const [me] = createResource(() => mePromise);
|
||||||
|
|
||||||
const playerProfiles: {
|
const playerProfiles: {
|
||||||
[humanKey: string]: Resource<ApiType<typeof api.profile.get>>;
|
[humanKey: string]: Resource<ApiType<typeof api.profile.get>>;
|
||||||
|
|||||||
@@ -9,11 +9,19 @@ import { human } from "./human";
|
|||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import db from "./db";
|
import db from "./db";
|
||||||
import { liveTable, WsOut, WsIn } from "./table";
|
import { liveTable, WsOut, WsIn } from "./table";
|
||||||
|
import { Human } from "@prisma/client";
|
||||||
|
|
||||||
const api = new Elysia({ prefix: "/api" })
|
const api = new Elysia({ prefix: "/api" })
|
||||||
.post("/whoami", async ({ cookie: { token } }) => {
|
.post("/whoami", async ({ cookie: { token } }) => {
|
||||||
let human;
|
let human: Human | null;
|
||||||
if (token.value == null) {
|
if (
|
||||||
|
token.value == null ||
|
||||||
|
(human = await db.human.findUnique({
|
||||||
|
where: {
|
||||||
|
token: token.value,
|
||||||
|
},
|
||||||
|
})) == null
|
||||||
|
) {
|
||||||
human = await db.human.create({
|
human = await db.human.create({
|
||||||
data: {},
|
data: {},
|
||||||
});
|
});
|
||||||
@@ -22,13 +30,8 @@ const api = new Elysia({ prefix: "/api" })
|
|||||||
expires: dayjs().add(1, "year").toDate(),
|
expires: dayjs().add(1, "year").toDate(),
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
human = await db.human.findUniqueOrThrow({
|
|
||||||
where: {
|
|
||||||
token: token.value,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return human.key;
|
return human.key;
|
||||||
})
|
})
|
||||||
.use(human)
|
.use(human)
|
||||||
|
|||||||
Reference in New Issue
Block a user