Skip to content
Open
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
6 changes: 3 additions & 3 deletions middlewares/config/jwtOption.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
module.exports = {
secretKey: '임강준현영구', // 원하는 시크릿
secretKey: 'Capella', // 원하는 시크릿
options: {
algorithm: "HS256", // 해싱 알고리즘
expiresIn: "1h", // 토큰 유효 기간
issuer: "dokdogalmaegi" // 발행자
issuer: "LeeSangHuck" // 발행자
},
refreshTokenOptions: {
algorithm: "HS256", // 해싱 알고리즘
expiresIn: "14d", // 토큰 유효 기간
issuer: "dokdogalmaegi" // 발행자
issuer: "LeeSangHuck" // 발행자
}
}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 45 additions & 2 deletions routes/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,51 @@ router.post('/signIn', async (req, res) => {
});

// 1. 임의 User의 name을 바꾸는 API를 구현하시면 됩니다.
router.post('/changeUsername', authUtil, async (req, res) => {
return res.json(util.success('test', 'test', 'test'));
router.post("/changeUsername", authUtil, async (req, res) => {

const id = req.body;
const changeUsername = req.body;
const user = await User.findOne({ id });

try {
if (!id) {
throw USER_ID;
} else if (!changeUsername) {
throw changeUsername;
}

if (!user) {
throw NOT_EXISTS_USER;
}

await User.updateOne({ id: user.id }, { $set: { name: changeUsername } });

return res.json(
util.success("SUCCESS_CHANGE_USER_NAME", "Success change user name!")
);
} catch ({ code, message }) {
switch (code) {
case USER_ID.code:
return res.json(util.fail(USER_ID.code, USER_ID.message));

case USER_PASSWORD.code:
return res.json(util.fail(USER_PASSWORD.code, USER_PASSWORD.message));

case NOT_EXISTS_USER.code:
return res.json(
util.fail(NOT_EXISTS_USER.code, NOT_EXISTS_USER.message)
);
case IN_KOREAN.code:
return res.json(util.fail(IN_KOREAN.code, IN_KOREAN.message));

case EXISTS_ID.code:
return res.json(util.fail(EXISTS_ID.code, EXISTS_ID.message));

default:
console.log(message);
return res.json(util.fail(OTHER.code, OTHER.message));
}
}
});

module.exports = router;