Skip to content

Commit

Permalink
Merge pull request #22 from Murakano/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
jjikky authored Jul 2, 2024
2 parents 5b06f68 + 38e8e51 commit 4cfb58d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 9 additions & 6 deletions src/routes/user/user.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,13 @@ exports.localLogin = async (req, res, next) => {
const accessToken = generateAccessToken(user);
const refreshToken = generateRefreshToken(user);

res.cookie('accessToken', accessToken, config.cookieInAccessTokenOptions);
res.cookie('refreshToken', refreshToken, config.cookieInRefreshTokenOptions);

return sendResponse.ok(res, {
message: SucesssMessage.LOGIN_SUCCESSS,
data: {
accessToken: accessToken,
},
});
})(req, res, next);
} catch (err) {
Expand All @@ -130,11 +132,13 @@ exports.kakaoLogin = async (req, res) => {

const accessToken = generateAccessToken(user);
const refreshToken = generateRefreshToken(user);
res.cookie('accessToken', accessToken, config.cookieInAccessTokenOptions);
res.cookie('refreshToken', refreshToken, config.cookieInRefreshTokenOptions);

sendResponse.ok(res, {
message: SucesssMessage.LOGIN_SUCCESSS,
data: {
accessToken: accessToken,
},
});
} catch (err) {
sendResponse.fail(req, res, ErrorMessage.KAKAO_LOGIN_ERROR);
Expand All @@ -160,13 +164,13 @@ exports.refreshToken = async (req, res) => {
const newAccessToken = generateAccessToken({ _id: user.userId, nickname: user.nickname, email: user.email });
const newRefreshToken = generateRefreshToken({ _id: user.userId, nickname: user.nickname, email: user.email });

res.cookie('accessToken', newAccessToken, config.cookieInAccessTokenOptions);
res.cookie('refreshToken', newRefreshToken, config.cookieInRefreshTokenOptions);

sendResponse.ok(res, {
message: SucesssMessage.REFRESH_TOKEN,
newAccessToken: newAccessToken,
newRefreshToken: newRefreshToken,
data: {
accessToken: newAccessToken,
},
});
});
};
Expand All @@ -181,7 +185,6 @@ exports.getProfile = (req, res) => {
};

exports.logout = (_, res) => {
res.clearCookie('accessToken');
res.clearCookie('refreshToken');
return sendResponse.ok(res, {
message: SucesssMessage.LOGOUT_SUCCESS,
Expand Down
2 changes: 1 addition & 1 deletion src/routes/user/user.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const userSchema = new mongoose.Schema(
maxlength: 50,
match: /^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$/,
},
password: { type: String, minLength: 8, maxLength: 20 },
password: { type: String },
role: { type: String, enum: ['user', 'admin'], default: 'user' },
snsId: { type: String, default: null },
provider: { type: String, enum: ['kakao'], default: null },
Expand Down

0 comments on commit 4cfb58d

Please sign in to comment.