[TIL] 211226

Lee Syong·2021년 12월 26일
0

TIL

목록 보기
130/204
post-thumbnail

📝 오늘 한 것

  1. 복습 - USER PROFILE

  2. 복습 - WEBPACK


📚 배운 것 (복습)

실제 코드는 github에 올림(wetube_v2)

5. USER PROFILE

  • [TIL] 211204

    • edit profile
    • avatar 파일 업로드
    • git restore --staged / get fetch
  • [TIL] 211205

    • video 파일 업로드
    • populate()
    • user profile
    • 버그 수정
      (1) 영상을 올릴 때마다 패스워드가 해싱되는 문제 해결
      (2) owner가 아닌 로그인 user도 video 수정/삭제가 가능한 문제 해결

💡 user.save() 할 때마다 패스워드가 해싱되는 문제 해결

  • this.isModified("password")를 추가해 user.save()를 사용해도 비밀번호가 변경될 때만 pre hook이 실행되도록 함
  • !this.socialOnly를 추가해 github 정보를 바탕으로 계정 생성 시에는 user.save()를 사용해도 pre hook이 실행되지 않도록 함 ❗ (복습하면서 새롭게 추가한 부분)
// User.js
userSchema.pre("save", async function () {
  if (!this.socialOnly && this.isModified("password")) {
    this.password = await bcrypt.hash(this.password, 5);
  }
});

💡 populated fields에 sort() 적용 (복습하면서 새롭게 추가한 부분)

const user = await User.findById(id).populate({
  path: "videos",
  options: {
    sort: { createdAt: "desc" },
  },
});

6. WEBPACK

  • [TIL] 211206
    • user profile 복습
    • webpack 설치 및 사용법
      • entry / output / rules(babel-loader) / mode
      • MiniCssExtractPlugin / css-loader / sass-loader
      • watch / clean / nodemon.json(ignore, exec) / dev:server, dev:assets

✨ 내일 할 것

  1. 복습 계속하기 - CSS 스타일링
profile
능동적으로 살자, 행복하게😁

0개의 댓글