Skip to content

Commit 056bab4

Browse files
committed
Merge branch 'ganghee' of https://github.com/CuseMe/CuseMe-Server
2 parents 38028c6 + af8124b commit 056bab4

File tree

5 files changed

+23
-2
lines changed

5 files changed

+23
-2
lines changed

controllers/userController.js

+9
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,14 @@ module.exports = {
4242
.catch(err => {
4343
res.status(err.status || 500)
4444
.send(util.successFalse(err.status, err.message))})
45+
},
46+
refresh: async (req, res) => {
47+
User.refreshToken(req.body)
48+
.then(result =>
49+
res.status(status.OK)
50+
.send(util.successTrue(status.OK, message.REFRESH_TOKEN_SUCCESS, result)))
51+
.catch(err => {
52+
res.status(err.status || 500)
53+
.send(util.successFalse(err.status, err.message))})
4554
}
4655
}

model/user.js

+9
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,14 @@ module.exports = {
7070
const value = [phoneNum, userIdx];
7171
const result = await db.queryParam_Parse(query, value);
7272
return result;
73+
},
74+
refreshToken: async ({uuid}) => {
75+
const findUserQuery = `SELECT * FROM ${TABLE} WHERE uuid = ?`;
76+
const findUserValues = [uuid];
77+
const findUserResult = await db.queryParam_Parse(findUserQuery, findUserValues);
78+
const user = findUserResult[0];
79+
const userIdx = user.userIdx;
80+
const jwtToken = jwtExt.publish({userIdx, uuid});
81+
return {token :jwtToken.token};
7382
}
7483
}

modules/security/jwt.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ module.exports = {
2828
} catch(err){
2929
if(err.message === 'jwt expired'){
3030
console.log('expired token');
31-
return -3;
31+
return -1;
3232
} else if(err.message === 'invalid token'){
3333
console.log('invalid token');
3434
return -2;
3535
} else{
3636
console.log('other problem');
37-
return -2;
37+
return -3;
3838
}
3939
}
4040
return decoded;

modules/utils/responseMessage.js

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ module.exports = {
1717
USER_UPDATE_FAIL:"유저 추가 실패",
1818
EXIST_DATA: "데이터가 있습니다.",
1919
NO_DATA:"데이터가 없습니다.",
20+
REFRESH_TOKEN_SUCCESS:"리프래시 토큰 성공",
21+
REFRESH_TOKEN_FAIL:"리프래시 토큰 실패",
2022

2123
PHONE_NUM_UPDATE_SUCCESS: "전화번호 변경 성공",
2224

routes/user.js

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const {LoggedIn} = require('../modules/utils/authUtil');
55

66
router.post('/start',AuthControllers.start);
77
router.post('/signIn', AuthControllers.signIn);
8+
router.get('/refresh', AuthControllers.refresh);
89
router.put('/', LoggedIn, AuthControllers.updatePwd)
910
router.put('/phone', LoggedIn, AuthControllers.updatePhone);
1011

0 commit comments

Comments
 (0)