Study
-
auth 기능 구현Study/Node, React 기초 강의_John Ahn 2023. 2. 19. 13:05
루트 디렉터리에 middleware 폴더 생성 middleware 폴더에 auth.js 구현 // User 모델을 불러옴 const { User } = require('../models/User'); let auth = (req, res, next) => { // 인증 처리를 하는 곳 // 클라이언트 쿠키에서 토큰을 가져온다. let token = req.cookies.x_auth; // 토큰을 복호화한 후 유저를 찾는다. User.findByToken(token, (err, user) => { if (err) throw err; if (!user) return res.json({ isAuth: false, error: true }) req.token = token; req.user = user; nex..
-
토큰 생성Study/Node, React 기초 강의_John Ahn 2023. 2. 19. 11:24
JSONWEBTOKEN 라이브러리 설치 npm install jsonwebtoken --save User.js에 토큰 생성함수 추가 // mongoose를 요청함 const mongoose = require('mongoose'); // bcrypt를 요청 const bcrypt = require('bcrypt'); // Salt를 이용해서 비밀번호를 암호화 해야하기 때문에 saltRounds를 설정 const saltRounds = 10 // jsonwebtoken 요청 const jwt = require('jsonwebtoken'); // Schema 설정 const userSchema = mongoose.Schema({ name: { type: String, maxlength: 50 }, email:..
-
로그인 기능 구현Study/Node, React 기초 강의_John Ahn 2023. 2. 19. 10:41
User.js의 userSchema.pre에서 비밀번호 변경 외의 다른 작업을 진행할 시 그다음단계로 진행시키기 위해 else문을 추가한다. // mongoose를 요청함 const mongoose = require('mongoose'); // bcrypt를 요청 const bcrypt = require('bcrypt'); // Salt를 이용해서 비밀번호를 암호화 해야하기 때문에 saltRounds를 설정 const saltRounds = 10 // Schema 설정 const userSchema = mongoose.Schema({ name: { type: String, maxlength: 50 }, email: { type: String, trim: true, unique: 1 }, password:..
-
Bcrypt를 이용한 비밀번호 암호화Study/Node, React 기초 강의_John Ahn 2023. 2. 19. 01:24
데이터베이스 관리자도 회원의 비밀번호를 모르게 하기 위해 Bcrypt를 사용한다. Bcrypt 설치 npm install bcrypt --save Bcrypt을 이용한 암호화 Bcrypt를 이용하여 암호화하기 위해 User.js에 userSchema.pref를 구현한다. userSchema.pre는 index.js의 app.post에서 user.save가 실행되기 전에 실행된다. // mongoose를 요청함 const mongoose = require('mongoose'); // bcrypt를 요청 const bcrypt = require('bcrypt'); // Salt를 이용해서 비밀번호를 암호화 해야하기 때문에 saltRounds를 설정 const saltRounds = 10..
-
비밀 설정 정보 관리Study/Node, React 기초 강의_John Ahn 2023. 2. 19. 00:51
github에 commit 할 때 mongodb의 아이디, 비밀번호를 유출시키지 않기 위하여 dev.js에 따로 mongodb 아이디 비밀번호에 관한 정보를 빼놓은 후. gitignore 파일에 dev.js 파일을 포함시킨다. dev.js module.export = { mongoURI: 'mongodb+srv://:@boilerplate.6t2ootw.mongodb.net/?retryWrites=true&w=majority' } .gitignore node_modules dev.js 개발 진행 시 Local development 환경에서의 개발과 Deploy(배포) 한 후 개발(production)로 나누어 지는데 prod.js에 Deploy(배포)한 후 mongodb에 연결될 수 있도록 구현하고 de..
-
NodemonStudy/Node, React 기초 강의_John Ahn 2023. 2. 14. 00:14
Nodemon이란? 소스를 변경할 때 그걸 감지해서 자동으로 서버를 재 시작해주는 툴이다. Visual Studio Code의 콘솔창에 명령어를 입력해 Nodemon을 설치한다. npm install nodemon --save-dev Nodemon을 이용하여 index.js를 실행하기 위해 package.json에 코드를 추가한다. { "name": "boilerplate", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "start": "node index.js", "backend": "nodemon index.js", "test": "echo \"Error: no test specified\" && exit..
-
BodyParser & PostMan & 회원 가입 기능Study/Node, React 기초 강의_John Ahn 2023. 2. 13. 23:24
BodyParser Client에서 보내주는 자료들을 받는 역할을 한다. BodyParser 설치 아래의 코드를 Visual Studio Code콘솔에 입력한다. npm install body-parser --save PostMan 설치 아래의 사이트에서 다운로드를 진행한다. https://www.postman.com/downloads/ Download Postman | Get Started for Free Try Postman for free! Join 20 million developers who rely on Postman, the collaboration platform for API development. Create better APIs—faster. www.postman.com ..
-
SSH를 이용하여 GITHUB 연결Study/Node, React 기초 강의_John Ahn 2023. 2. 13. 22:32
GitHub 계정 생성 및 로그인 GitHub 계정이 없는 경우 회원가입을 해주고 계정이 있다면 로그인을 진행한다. https://github.com/ GitHub: Let’s build from here GitHub is where over 100 million developers shape the future of software, together. Contribute to the open source community, manage your Git repositories, review code like a pro, track bugs and fea... github.com 새로운 repository를 생성한다. SSH 키 생성 및 ssh-agent에 추가 아래의 사이트에서 사용자의 컴퓨터 환경에 맞..