update cuz presentation
This commit is contained in:
parent
7a9e451739
commit
4e67cc4e19
29 changed files with 1065 additions and 88 deletions
25
server/utils/getRequestingUser.ts
Normal file
25
server/utils/getRequestingUser.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
/* 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<user>;
|
||||
|
||||
if (!user) throw createError("User not found");
|
||||
return user;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue