WorkshopTasker/server/api/users/me.get.ts
2023-05-11 06:03:22 +02:00

14 lines
604 B
TypeScript

/* global defineEventHandler, getCookie */
import { database, data } from "~/server/utils/database";
import { user } from "~/utils/types/database";
export default defineEventHandler(async (e) => {
const token = getCookie(e, "token");
const [[userData]] = await database.query(
"SELECT CONVERT(`users`.`id`, CHAR(32)) as `id`, `users`.`username` as `username`, `users`.`email` as `email`, `users`.`display_name` as `display_name` FROM `sessions` LEFT JOIN `users` ON `sessions`.`user` = `users`.`id` WHERE `sessions`.`id` = ?",
[token],
) as unknown as data<user>;
return userData;
});