From 3cdfe77a2a2d1a8e8a3fa52b40e2c28211b7e358 Mon Sep 17 00:00:00 2001 From: jjikky Date: Sun, 14 Jul 2024 22:08:12 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20redis=20RT=20TTL=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9=20=EB=B0=8F=20mismatch=EC=8B=9C=20=EB=AC=B4?= =?UTF-8?q?=ED=9A=A8=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/routes/user/user.controller.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/routes/user/user.controller.js b/src/routes/user/user.controller.js index 02d3760..c2ca957 100755 --- a/src/routes/user/user.controller.js +++ b/src/routes/user/user.controller.js @@ -103,7 +103,7 @@ exports.localLogin = async (req, res, next) => { const accessToken = generateAccessToken(user); const refreshToken = generateRefreshToken(user); - await redisClient.set(user.email, refreshToken); + await redisClient.set(user.email, refreshToken, 'EX', 60 * 60 * 12); res.cookie('refreshToken', refreshToken, config.cookieInRefreshTokenOptions); @@ -136,9 +136,7 @@ exports.kakaoLogin = async (req, res) => { } const accessToken = generateAccessToken(user); - const refreshToken = generateRefreshToken(user); - console.log(user.email); - const re = await redisClient.set(user.email, refreshToken); + const re = await redisClient.set(user.email, refreshToken, 'EX', 60 * 60 * 12); console.log('hh', re); res.cookie('refreshToken', refreshToken, config.cookieInRefreshTokenOptions); @@ -172,6 +170,9 @@ exports.refreshToken = async (req, res) => { const storedRefreshToken = await redisClient.get(user.email); if (storedRefreshToken !== refreshToken) { + console.error('Refresh token mismatch'); + await redisClient.del(user.email); + res.clearCookie('refreshToken', config.cookieInRefreshTokenDeleteOptions); return sendResponse.unAuthorized(res, { message: ErrorMessage.REFRESH_TOKEN_MISMATCH, }); @@ -188,7 +189,7 @@ exports.refreshToken = async (req, res) => { email: user.email, }); - await redisClient.set(user.email, newRefreshToken); + await redisClient.set(user.email, newRefreshToken, 'EX', 60 * 60 * 12); res.cookie('refreshToken', newRefreshToken, config.cookieInRefreshTokenOptions); sendResponse.ok(res, { From 5d695b17a6b06afa7da31f8986fc058a29c98756 Mon Sep 17 00:00:00 2001 From: jjikky Date: Sun, 14 Jul 2024 22:35:55 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20kakaoLogin=20=EC=9D=B4?= =?UTF-8?q?=EC=A0=84=EC=BB=A4=EB=B0=8B=20=EC=8B=A4=EC=88=98=20=EB=B3=B5?= =?UTF-8?q?=EA=B5=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/routes/user/user.controller.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/routes/user/user.controller.js b/src/routes/user/user.controller.js index c2ca957..a1f4aea 100755 --- a/src/routes/user/user.controller.js +++ b/src/routes/user/user.controller.js @@ -136,8 +136,9 @@ exports.kakaoLogin = async (req, res) => { } const accessToken = generateAccessToken(user); - const re = await redisClient.set(user.email, refreshToken, 'EX', 60 * 60 * 12); - console.log('hh', re); + const refreshToken = generateRefreshToken(user); + + await redisClient.set(user.email, refreshToken, 'EX', 60 * 60 * 12); res.cookie('refreshToken', refreshToken, config.cookieInRefreshTokenOptions); sendResponse.ok(res, {