/* global getCookie, createError */ import { H3Event } from "h3"; import { database, data } from "./database"; import { user } from "~/utils/types/database"; export default async function getRequestingUser(e: H3Event) { const cookie = getCookie(e, "token"); const [[user]] = await database.query( ["SELECT", "CONVERT(`users`.`id`, CHAR) as `id`,", "`users`.`username`,", "`users`.`email`,", "`users`.`display_name`", "FROM", "`sessions`", "LEFT JOIN `users` ON `sessions`.`user` = `users`.`id`", "WHERE `sessions`.`id` = ?", ].join(" "), [cookie], ) as data; if (!user) throw createError("User not found"); return user; }