반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 운동일지
- JavaScript
- Til
- 월별 운동일지
- git
- express
- 걷기
- MySQL
- dml
- 크로스핏
- 홈트
- wecode
- 달리기
- axios
- SQL
- 위코드
- 러닝
- 활동 킬로칼로리
- 박스점프
- node
- 독서 리뷰
- 드림코딩
- node.js
- Udemy
- github
- 메디패치
- 습윤밴드
- nodejs
- code kata
- dql
Archives
- Today
- Total
RISK IT
[TIL28_23.2.5.] [Node] pw 및 email 유효성검사 파일 utils 폴더에 추가 본문
반응형
pw 및 email 유효성검사 파일 utils 폴더에 추가
📔 작업내용
pw 및 email 유효성검사 파일 utils 폴더에 추가
🧑🏻💻 코드
📑 /services/userService.js
const signUp = async (name, email, password, profileImage) => {
await validate.validatePassword(password);
await validate.validateEmail(email);
const [userInfo] = await userDao.getUserByEmail(email);
if (userInfo) {
const err = new Error('Email Already Exists.');
err.code = 400;
throw err;
}
const saltRounds = 12;
const hashPassword = await bcrypt.hash(password, saltRounds);
const createUser = await userDao.createUser(
name,
email,
hashPassword,
profileImage
);
return createUser;
};
📑 /utils/validate-user.js
const validatePassword = async (password) => {
const pwValidation = new RegExp(
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[~!@$#$%^&*\-?])[A-Za-z\d~!@$#$%^&*\-?]{8,}/
);
if (!pwValidation.test(password)) {
const err = new Error('🔐 Password Is Invalid Format');
err.code = 400;
throw err;
}
};
const validateEmail = async (email) => {
const emailValidation = new RegExp(
/^[a-zA-Z0-9+-\_.]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$/
);
if (!emailValidation.test(email)) {
const err = new Error('📧 Email Is Invalid Format');
err.code = 400;
throw err;
}
};
module.exports = { validatePassword, validateEmail };
반응형
'IT > TIL' 카테고리의 다른 글
[TIL30_23.2.7.] [1st-project] [Git&Github] PR 시 고려사항 (0) | 2023.02.08 |
---|---|
[TIL29_23.2.6.] [1st-project] [Git&Github] 프로젝트 시작 시 clone 정리 (0) | 2023.02.07 |
[TIL27_23.2.4.] [회고] 위코드 1~3주차 Precouse & Foundation-1, 2 과정 회고 (0) | 2023.02.04 |
[TIL26_23.2.3.] [Javascript] 정규표현식 정리 (0) | 2023.02.03 |
[TIL25_23.2.2.] [Node] 프론트엔드와의 첫 통신 & 유저 회원가입 오류 디버깅 (0) | 2023.02.03 |