Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/controllers/auth.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,23 +174,23 @@ export const handleGetAccountInfo = async (req, res, next) => {
}
}

export const handleResetPassword = async (req, res, next) => {
export const handleChangePassword = async (req, res, next) => {
const userId = req.user.id;
const {oldPassword, newPassword} = req.body;
try{
const result = await resetPassword({userId, oldPassword, newPassword});
const result = await changePassword({userId, oldPassword, newPassword});

res.status(200).success(result);
} catch(err) {
next(err);
}
}

export const handleChangePassword = async (req, res, next) => {
export const handleResetPassword = async (req, res, next) => {
const userId = req.user.id;
const {password} = req.body;
try{
const result = await changePassword({userId, password});
const result = await resetPassword({userId, password});

res.status(200).success(result);
} catch(err) {
Expand Down
4 changes: 2 additions & 2 deletions src/schemas/auth.schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ export const usernameSchema = z.object({
})
})

export const changePasswordSchema = z.object({
export const resetPasswordSchema = z.object({
body: z.object({
password: passwordPart
})
})

export const resetPasswordSchema = z.object({
export const changePasswordSchema = z.object({
body: z.object({
oldPassword: passwordPart,
newPassword: passwordPart
Expand Down
16 changes: 8 additions & 8 deletions src/services/auth.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,14 @@ export const getAccountInfo = async (email) => {
}
}

export const resetPassword = async ({userId, oldPassword, newPassword}) => {
export const resetPassword = async ({userId, password}) => {
const newPasswordHash = await bcrypt.hash(password, 10);
await updatePassword({userId, newPassword: newPasswordHash});

return { message: "비밀번호 재설정이 완료되었습니다." };
}

export const changePassword = async ({userId, oldPassword, newPassword}) => {
const oldPasswordHash = await getHashedPasswordByUserId(userId);
if(!oldPasswordHash) throw new PasswordNotFoundError("PASSWORD_NOT_FOUND", "기존 비밀번호를 찾을 수 없습니다.");

Expand All @@ -300,12 +307,5 @@ export const resetPassword = async ({userId, oldPassword, newPassword}) => {
const newPasswordHash = await bcrypt.hash(newPassword, 10);
await updatePassword({userId, newPassword: newPasswordHash});

return { message: "비밀번호 재설정이 완료되었습니다." };
}

export const changePassword = async ({userId, password}) => {
const newPasswordHash = await bcrypt.hash(password, 10);
await updatePassword({userId, newPassword: newPasswordHash});

return { message: "비밀번호 재설정이 완료되었습니다." };
}
12 changes: 6 additions & 6 deletions src/swagger/auth.swagger.js
Original file line number Diff line number Diff line change
Expand Up @@ -689,10 +689,10 @@

/**
* @swagger
* /auth/reset-password:
* /auth/change-password:
* patch:
* summary: 비밀번호 초기화
* description: "/auth/reset-password/confirm 에서 발급받은 임시 AccessToken이 필요합니다."
* summary: 비밀번호 변경
* description: "비밀번호 변경 API입니다."
* tags: [로그인]
* security:
* - bearerAuth: []
Expand Down Expand Up @@ -812,10 +812,10 @@

/**
* @swagger
* /auth/change-password:
* /auth/reset-password:
* patch:
* summary: 비밀번호 변경
* description: "비밀번호 변경 API입니다."
* summary: 비밀번호 초기화
* description: "/auth/reset-password/confirm 에서 발급받은 임시 AccessToken이 필요합니다."
* tags: [로그인]
* security:
* - bearerAuth: []
Expand Down