From a949d0d1f3f49bb6177d1da836604f66902e9501 Mon Sep 17 00:00:00 2001 From: Yunus <19399214+yunusefendi52@users.noreply.github.com> Date: Sun, 31 Mar 2024 22:28:06 +0700 Subject: [PATCH] ok --- server/middleware/auth-middleware.ts | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/server/middleware/auth-middleware.ts b/server/middleware/auth-middleware.ts index 63a7aa6..db5b289 100644 --- a/server/middleware/auth-middleware.ts +++ b/server/middleware/auth-middleware.ts @@ -13,16 +13,17 @@ declare module 'h3' { export default defineEventHandler((event) => { - // const appAuth = getCookie(event, 'app-auth') - // if (appAuth) { - // const verifiedData = jsonwebtoken.verify(appAuth, JWT_KEY) - // // if (!verifiedData) { - // // deleteCookie(event, 'app-auth') - // // } - // // @ts-ignore - // const userId = verifiedData.userId - // event.context.auth = { userId: userId } - // } else { - // } - event.context.auth = { userId: 1 } + const appAuth = getCookie(event, 'app-auth') + if (appAuth) { + const verifiedData = jsonwebtoken.verify(appAuth, JWT_KEY) + // if (!verifiedData) { + // deleteCookie(event, 'app-auth') + // } + // @ts-ignore + const userId = verifiedData.userId + event.context.auth = { userId: userId } + } else { + console.log('user not logged in') + event.context.auth = { userId: 1 } + } })