Replace mysql2 with prisma
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
This commit is contained in:
parent
be1e3909b6
commit
eebf25198d
39 changed files with 1081 additions and 1292 deletions
|
@ -1,7 +1,8 @@
|
|||
import { defineEventHandler, getCookie } from "h3";
|
||||
import { createError } from "#imports";
|
||||
|
||||
import { database, type data } from "~/server/utils/database";
|
||||
import { database } from "~/server/utils/database";
|
||||
import getRequestingUser from "~/server/utils/getRequestingUser";
|
||||
|
||||
const endpointsWithoutAuth: string[] = [
|
||||
"/dbtest",
|
||||
|
@ -34,13 +35,14 @@ export default defineEventHandler(async (e) => {
|
|||
export async function isAuthorised(token: string | undefined): Promise<boolean> {
|
||||
if (!token) return false;
|
||||
try {
|
||||
const [[session]] = await database.query(
|
||||
"SELECT EXISTS(SELECT `id` FROM `sessions` WHERE `id` = ? AND `expiry_date` >= NOW()) as `logged_in`",
|
||||
[token],
|
||||
) as unknown as data<{logged_in: number}>;
|
||||
await database.session.findUniqueOrThrow({
|
||||
where: {
|
||||
id: BigInt(token),
|
||||
},
|
||||
});
|
||||
|
||||
return session.logged_in === 1;
|
||||
} catch {
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue