router.post('/', async (req, res, next) => {
// POST /api/user 회원가입
try {
const exUser = await db.User.findOne({
where: {
email: req.body.email,
},
});
const affliationId = await db.Affliations.findOne({
where: {
name: req.body.affliations,
},
});
if (exUser) {
return res.status(403).send('이미 사용중인 아이디입니다.');
}
회원가입시 입력한 email
이 User
테이블에 존재한다면 res.status(403).send('이미 사용중인 아이디입니다.')
이 코드를 반환한다.
// sagas
try {
yield call(signUpAPI, action.data);
yield put({
type: SIGN_UP_SUCCESS,
});
} catch (e) {
// loginAPI 실패
console.log('e ? ', e);
console.log('e ? ', e.response.data);
yield put({
type: SIGN_UP_FAILURE,
error: e.response.data,
});
}
[ console.log ] e / e.response.data ▼
[ console.log ] e.response ▼
res.status(403).send('이미 사용중인 아이디입니다.');
를 반환하게 되면 catch
의 e.response.data
에 담기게된다.
// reducer
case SIGN_UP_FAILURE: {
draft.isSigningUp = false;
draft.isSignedUp = false;
console.log('action ? ', action);
draft.signUpErrorReason = action.error;
break;
}
action.error
에 담긴 문구를 받아 이메일이 중복되면 alert
에 넣어 띄워주면 된다!