Wroclaw
eebf25198d
also I updated packages, and properly typed api input a lot of time was spent, I don't remeber what really I did x3 but everything was related to replacing mysql2 with prisma
31 lines
714 B
TypeScript
31 lines
714 B
TypeScript
import { getCookie, H3Event } from "h3";
|
|
|
|
import { database } from "./database";
|
|
|
|
import { createError } from "#imports";
|
|
|
|
export default async function getRequestingUser(e: H3Event) {
|
|
const cookie = getCookie(e, "token");
|
|
if (!cookie) throw createError("User not found");
|
|
const { user } = await database.session.findUnique({
|
|
where: {
|
|
id: BigInt(cookie),
|
|
},
|
|
select: {
|
|
user: {
|
|
select: {
|
|
display_name: true,
|
|
email: true,
|
|
id: true,
|
|
username: true,
|
|
},
|
|
},
|
|
},
|
|
}).then((e) => {
|
|
if (e === null) throw createError("User not found");
|
|
return e;
|
|
});
|
|
|
|
if (!user) throw createError("User not found");
|
|
return user;
|
|
}
|