patch parsing JSON error

This commit is contained in:
Fanrouver
2026-01-07 07:50:25 +07:00
parent 21f6b63ce4
commit ab99ba2fe5
5 changed files with 22 additions and 48 deletions
+5 -14
View File
@@ -203,28 +203,19 @@ const initDb = () => {
export default defineEventHandler(async (event) => {
console.log("🔄 Sync all users endpoint called");
const sessionCookie = getCookie(event, "user_session");
// Get session from session store
const { getSessionFromCookie } = await import('~/server/utils/sessionStore');
const session = await getSessionFromCookie(event);
if (!sessionCookie) {
if (!session) {
throw createError({
statusCode: 401,
statusMessage: "No session cookie found",
statusMessage: "No session found or session expired",
});
}
try {
const config = useRuntimeConfig();
const session = JSON.parse(sessionCookie);
const isExpired = Date.now() > session.expiresAt;
if (isExpired) {
deleteCookie(event, "user_session");
throw createError({
statusCode: 401,
statusMessage: "Session expired",
});
}
const accessToken = session.accessToken;
if (!accessToken) {
throw createError({