Skip to content

Commit

Permalink
Merge pull request #19 from TeamBookTez/fix/login-api
Browse files Browse the repository at this point in the history
Fix/login api
  • Loading branch information
holmir97 authored Jan 12, 2022
2 parents 5b905fb + 0c07a75 commit c6f6b49
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
12 changes: 5 additions & 7 deletions src/controller/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,38 +100,36 @@ const postSignupController = async (req: Request, res: Response) => {

const postLoginController = async (req: Request, res: Response) => {
try {
const { email, password } = req.body;
const data = await authService.postLoginService(email, password);
const resData = await authService.postLoginService(req.body);

if (data === -1) {
if (resData === constant.NULL_VALUE) {
response.basicResponse(
res,
returnCode.BAD_REQUEST,
false,
"필요한 값이 없습니다."
);
} else if (data === -2) {
} else if (resData === -100) {
response.basicResponse(
res,
returnCode.NOT_FOUND,
false,
"존재하지 않는 이메일입니다."
);
} else if (data === -3) {
} else if (resData === -101) {
response.basicResponse(
res,
returnCode.BAD_REQUEST,
false,
"비밀번호가 일치하지 않습니다."
);
} else {
const { nickname, token } = data;
response.dataResponse(
res,
returnCode.OK,
"장서현의 첫 api 소중히 다뤄주세요 💋",
true,
data
resData
);
}
} catch (err) {
Expand Down
8 changes: 4 additions & 4 deletions src/service/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,22 @@ const postSignupService = async ({ email, nickname, password }) => {
* @access public
*/

const postLoginService = async (email: string, password: string) => {
const postLoginService = async ({ email, password }) => {
// 요청 바디 부족
if (!email || !password) {
return -1;
return constant.NULL_VALUE;
}

// 존재하지 않는 이메일
const user = await User.findOne({ where: { email: email } });
if (!user) {
return -2;
return -100;
}

// 비밀번호 일치 X
const isMatch = await bcrypt.compare(password, user.password);
if (!isMatch) {
return -3;
return -101;
}

// 성공 시
Expand Down

0 comments on commit c6f6b49

Please sign in to comment.