Skip to content

Commit

Permalink
fix: remove unused code about cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
ptyoiy committed May 17, 2024
1 parent 8d77494 commit eb1ed9a
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 13 deletions.
4 changes: 2 additions & 2 deletions controllers/jwt/jwt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ export const verifyToken = (req: Express.Request, res, next) => {
try {
const payload = jwt.verify(token, process.env.SECRET_KEY) as Payload;
if (payload.id != id) {
throw new Error('토큰과 다른 사용자.')
throw new Error(`토큰과 다른 사용자. payloadID:${payload.id}, ID:${id}`)
}
next();
} catch (error) {
if (error.name === 'TokenExpiredError') {
return res.status(419).json({ message: '토큰이 만료되었습니다.' });
}
// TODO: error.message 수정하기
return res.status(401).json({ message: '유효하지 않은 토큰입니다.' + ' ' + error.message });
return res.status(401).json({ message: '유효하지 않은 토큰입니다:' + error.message });
}
}

Expand Down
7 changes: 4 additions & 3 deletions controllers/user/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,14 @@ export const getRefreshToken = async (req: express.Request, res: express.Respons
};

export const logout = async (req: express.Request, res: express.Response) => {
const { accessToken, refreshToken } = req.cookies;
const { accessToken } = req.cookies;
const { refreshToken } = req.body;
try {
if (!accessToken) throw new Error("accessToken 없음");
if (!refreshToken) throw new Error("refreshToken 없음");
await redisClient.del(`refreshToken:${req.cookies.refreshToken}`);
await redisClient.del(`refreshToken:${refreshToken}`);
res.clearCookie("accessToken");
res.clearCookie("refreshToken");
res.clearCookie("id");
return res.status(200).json({ status: 1 });
} catch (e) {
console.error({ e });
Expand Down
3 changes: 1 addition & 2 deletions controllers/user/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ export const getUserInfo = async (req: express.Request, res: express.Response) =

return res.status(200).json(userInformation);
} catch (e) {
console.log({ e });
return res.status(500).json({ error: "서버 내부 에러" });
return res.status(500).json({ error: "서버 내부 에러", message: e });
}
}
6 changes: 0 additions & 6 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,6 @@ const start = async () => {
app.use(cookieParser());
app.use(json());
app.use(urlencoded({ extended: false }));
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", corsOptions.origin);
res.header("Access-Control-Allow-Credentials", 'true');
res.setHeader("Set-Cookie", "key=value; HttpOnly; SameSite=None")
next();
});
app.use("/api", noticeRouter);
app.use("/api", userRouter);
app.use("/api", eventRouter);
Expand Down

0 comments on commit eb1ed9a

Please sign in to comment.