Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/login api #19

Merged
merged 5 commits into from
Jan 12, 2022
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
14 changes: 6 additions & 8 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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 All @@ -146,7 +144,7 @@ const postLoginController = async (req: Request, res: Response) => {
}
};
const authController = {
postSignupController,
postSignupController,
postLoginController,
};

Expand Down
8 changes: 4 additions & 4 deletions src/service/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,22 @@ const postSignupService = async ({ email, nickname, password }) => {
* @access public
*/

const postLoginService = async (email: string, password: string) => {
const postLoginService = async ({ email, password }) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

req.body를 받을때 타입선언 하겠습니다

// 요청 바디 부족
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