Skip to content

Commit

Permalink
fix: logout method, redis cache expire
Browse files Browse the repository at this point in the history
  • Loading branch information
ptyoiy committed Mar 5, 2024
1 parent 575ccf7 commit ab5bd1b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion controllers/jwt/jwt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ enum TokenType {

export const verifyToken = (req: Express.Request, res, next) => {
const token = req.cookies.accessToken;
const id = req.params.id || req.cookies.id;
const id = req.params.id;
if (!token) {
return res.status(401).json({
code: 401,
Expand Down
4 changes: 2 additions & 2 deletions controllers/user/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ export const getRefreshToken = async (req: express.Request, res: express.Respons
};

export const logout = async (req: express.Request, res: express.Response) => {
const { accessToken } = req.body;
const { refreshToken } = req.cookies;
const { accessToken, refreshToken } = req.cookies;
try {
if (!accessToken) throw new Error("accessToken 없음");
if (!refreshToken) throw new Error("refreshToken 없음");
await redisClient.del(`refreshToken:${req.cookies.refreshToken}`);
res.clearCookie("accessToken");
res.clearCookie("refreshToken");
return res.status(200).json({ status: 1 });
} catch (e) {
Expand Down
8 changes: 4 additions & 4 deletions redis/initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ const initAllOngoingEvents = async () => {
}
for (const event of eventsFromDb) {
const eventRedisKey = `event:${event.id}`;
await redisClient.set(eventRedisKey, JSON.stringify(event), { EX: EXPIRE });
await redisClient.set(eventRedisKey, JSON.stringify(event));
}

// 전체 목록 캐싱
await redisClient.set(redisKey, JSON.stringify(eventsFromDb), { EX: EXPIRE });
await redisClient.set(redisKey, JSON.stringify(eventsFromDb));

console.log("전체 행사:", await redisClient.get(redisKey));
console.log("진행중인 행사:", eachEvents);
Expand Down Expand Up @@ -66,10 +66,10 @@ const initAllOngoingNotices = async (priority: '일반' | '긴급') => {
}
for (const notice of noticesFromDB) {
const redisKey = `notice:${notice.id}`;
await redisClient.set(redisKey, JSON.stringify(notice), { EX: EXPIRE });
await redisClient.set(redisKey, JSON.stringify(notice));
}
// 전체 공지 캐싱
await redisClient.set(redisKey, JSON.stringify(noticesFromDB), { EX: EXPIRE });
await redisClient.set(redisKey, JSON.stringify(noticesFromDB));

priority == '긴급' && console.log(`진행중인 공지: `, eachNotices);
}

0 comments on commit ab5bd1b

Please sign in to comment.