fix auth check if database is uninitialised
This commit is contained in:
parent
75f809051c
commit
cbfc4e9317
1 changed files with 10 additions and 5 deletions
|
@ -8,6 +8,7 @@ const endpointsWithoutAuth: string[] = [
|
|||
"/hi",
|
||||
"/login",
|
||||
"/logout",
|
||||
"/firstRun",
|
||||
];
|
||||
|
||||
export default defineEventHandler(async (e) => {
|
||||
|
@ -31,10 +32,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}>;
|
||||
|
||||
return session.logged_in === 1;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue