From 3f10759bd2f6679b8e31331143ae68b6ed59be21 Mon Sep 17 00:00:00 2001 From: Aseer KT Date: Fri, 26 Jul 2024 20:29:05 +0530 Subject: [PATCH] fix: logout/login sessions --- server/src/common/controllers.ts | 3 ++- server/src/redis/handlers.ts | 1 + server/src/redis/index.ts | 6 +++++- web/src/hooks/useAuth.ts | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/server/src/common/controllers.ts b/server/src/common/controllers.ts index 3db1090..9b42aaf 100644 --- a/server/src/common/controllers.ts +++ b/server/src/common/controllers.ts @@ -41,7 +41,7 @@ export const recreateAccessToken: RequestHandler = async (req, res) => { const isValid = await isRefreshTokenValid( refreshPayload.id, - refreshToken.tokenId, + refreshPayload.tokenId, refreshToken, ) @@ -74,6 +74,7 @@ export const logout: RequestHandler = async (req, res, next) => { } await invalidateRefreshToken(req.user!.id, refreshPayload.tokenId) clearRefreshTokenCookie(res) + res.sendStatus(200) } catch (error) { next(error) } diff --git a/server/src/redis/handlers.ts b/server/src/redis/handlers.ts index ab13f45..6692cc0 100644 --- a/server/src/redis/handlers.ts +++ b/server/src/redis/handlers.ts @@ -38,6 +38,7 @@ export const isRefreshTokenValid = async ( redisKeys.USER_TOKEN(userId), tokenId, ) + console.log('redis access token', redisToken, tokenId) return redisToken === token } diff --git a/server/src/redis/index.ts b/server/src/redis/index.ts index 24351f8..5988e23 100644 --- a/server/src/redis/index.ts +++ b/server/src/redis/index.ts @@ -1,11 +1,15 @@ import { config } from '@/config' + +if (!config.isProd) { + process.env.DEBUG = 'ioredis:*' +} + import Redis from 'ioredis' let redisClient: Redis export function getRedisClient() { if (!redisClient) { - process.env.DEBUG = config.isProd ? '' : 'ioredis:*' redisClient = new Redis({ host: config.redisHost, port: +config.redisPort, diff --git a/web/src/hooks/useAuth.ts b/web/src/hooks/useAuth.ts index 9c2b085..15d2dc9 100644 --- a/web/src/hooks/useAuth.ts +++ b/web/src/hooks/useAuth.ts @@ -24,7 +24,7 @@ export const useAuthSetter = () => { }, []) const clearAuth = useCallback(() => { - queryClient.setQueryData(['userToken'], () => undefined) + queryClient.setQueryData(['userToken'], () => null) // eslint-disable-next-line react-hooks/exhaustive-deps }, [])