bcyptjs는 데이터 암호화 할때 사용
bcryptjs
Optimized bcrypt in plain JavaScript with zero dependencies. Compatible to 'bcrypt'.. Latest version: 2.4.3, last published: 7 years ago. Start using bcryptjs in your project by running `npm i bcryptjs`. There are 3373 other projects in the npm registry us
www.npmjs.com
jsonwebtoken는 회원 인증(로그인)
jsonwebtoken - npm (npmjs.com)
jsonwebtoken
JSON Web Token implementation (symmetric and asymmetric). Latest version: 9.0.2, last published: 4 months ago. Start using jsonwebtoken in your project by running `npm i jsonwebtoken`. There are 26060 other projects in the npm registry using jsonwebtoken.
www.npmjs.com
모듈 설치
npm i bcryptjs jsonwebtoken
사용자 비밀번호 암호화, 로그인
인증 확인
aucthenticate.js
router에 인증확인 추가
router.js
테스트
1. 회원등록
2. DB에서 데이터 확인
패스워드가 암호화됨
3.로그인
성공시
실패시
4. 인증 확인
로그인 안하고 들어올시
Headers에 Authorization을 추가하고 Bearer 다음에 토큰을 넣어서 접속하면
employee에 접속할 수 있음
참고
NodeJS and MongoDB Tutorial #5 - User Login Registration (youtube.com)
'Javascript > nodejs' 카테고리의 다른 글
[Node.js] mongoose 페이지네이션 구현(pagination) (0) | 2024.01.02 |
---|---|
[Node.js]환경변수 설정(.env, dotenv) (0) | 2024.01.01 |
Mongoose findOne $or이 뭐지? (0) | 2023.12.30 |
[Node.js] 파일 업로드 (multer, 예제) (0) | 2023.12.30 |
[Node.js]Mongoose 사용 예시 (0) | 2023.12.26 |