patch parsing JSON error
This commit is contained in:
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user