From 63a7ffe822656615704f7baf06a92b3ef81aa6e5 Mon Sep 17 00:00:00 2001 From: Jieun Kim Date: Sun, 4 Feb 2024 22:15:07 +0900 Subject: [PATCH] =?UTF-8?q?feat(#88)=20:=20=ED=94=84=EB=A1=9C=ED=95=84=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20API=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controller/authController.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/controller/authController.js b/src/controller/authController.js index 1f90a29..30040b1 100644 --- a/src/controller/authController.js +++ b/src/controller/authController.js @@ -202,7 +202,7 @@ export const getUserInfo = async (req, res, next) => { */ export const updateUserInfo = async (req, res, next) => { const { _id, email } = req.user; - const { nickname, phone, profile_image, password } = req.body; + const { nickname, phone, password } = req.body; const fileUrl = req.file && req.file.location ? req.file.location @@ -230,6 +230,8 @@ export const updateUserInfo = async (req, res, next) => { } // password 수정 시, password 유효성 검사 & 암호화 + let hashedPassword; + if (password) { if (validPasswordCheck(password) == false) { return res.send( @@ -239,15 +241,18 @@ export const updateUserInfo = async (req, res, next) => { ) ); } - const hashedPassword = await bcrypt.hash(password, 10); + hashedPassword = await bcrypt.hash(password, 10); } // S3 업로드 된 이미지 삭제 const findUser = await User.findOne({ email }); - const fileKey = findUser.profile_image; - await deleteImage(fileKey); - console.log("이미지 삭제 성공"); + if (findUser.profile_image && findUser.profile_image !== "파일을 업로드하지 않았습니다.") { + const fileKey = findUser.profile_image; + await deleteImage(fileKey); + console.log("이미지 삭제 성공"); + } + const updateUser = await User.findOneAndUpdate( { email: email }, { @@ -255,7 +260,7 @@ export const updateUserInfo = async (req, res, next) => { nickname: nickname, phone: phone, profile_image: fileUrl, - password: password, + password: hashedPassword, }, }, { new: true }