mirror of
https://github.com/hpware/news-analyze.git
synced 2025-06-24 00:01:03 +08:00
this without issues in prod tho. and the "BlurPageBeforeLogin" thing works just file, oh and checkCookie is now working (but without the database part just yet)
48 lines
1.2 KiB
TypeScript
48 lines
1.2 KiB
TypeScript
// This should be hooked up to a database soon.
|
|
import postgres from "~/server/components/postgres";
|
|
|
|
// Parse Date Function
|
|
function checkDate(dateString: string) {
|
|
const now = new Date();
|
|
const parsed = new Date(dateString);
|
|
const timer = 60 * 60 * 1;
|
|
return now.getTime() - parsed.getTime() > timer;
|
|
}
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const loginCookie = getCookie(event, "session");
|
|
const lastCheckCookie = getCookie(event, "last_check");
|
|
const nowDate = new Date().toLocaleString();
|
|
console.log(nowDate);
|
|
if (!lastCheckCookie && loginCookie) {
|
|
deleteCookie(event, "session");
|
|
setCookie(event, "lastCheckCookie", nowDate, {
|
|
httpOnly: true,
|
|
secure: process.env.NODE_ENV === "production",
|
|
path: "/",
|
|
});
|
|
return {
|
|
auth: false,
|
|
user: null,
|
|
};
|
|
}
|
|
if (!lastCheckCookie) {
|
|
setCookie(event, "lastCheckCookie", nowDate, {
|
|
httpOnly: true,
|
|
secure: process.env.NODE_ENV === "production",
|
|
path: "/",
|
|
});
|
|
}
|
|
if (checkDate(String(lastCheckCookie))) {
|
|
setCookie(event, "lastCheckCookie", nowDate, {
|
|
httpOnly: true,
|
|
secure: process.env.NODE_ENV === "production",
|
|
path: "/",
|
|
});
|
|
}
|
|
return {
|
|
auth: true,
|
|
user: "testing",
|
|
};
|
|
});
|