Skip to content

Commit

Permalink
Merge pull request #59 from Murakano/feature/auth
Browse files Browse the repository at this point in the history
Feature/auth - redis RT TTL 적용 및 mismatch시 무효화
  • Loading branch information
jjikky authored Jul 14, 2024
2 parents 84b39ea + 5d695b1 commit b66c461
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/routes/user/user.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -137,9 +137,8 @@ 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);
console.log('hh', re);

await redisClient.set(user.email, refreshToken, 'EX', 60 * 60 * 12);
res.cookie('refreshToken', refreshToken, config.cookieInRefreshTokenOptions);

sendResponse.ok(res, {
Expand Down Expand Up @@ -172,6 +171,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,
});
Expand All @@ -188,7 +190,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, {
Expand Down

0 comments on commit b66c461

Please sign in to comment.