유저별로 API에 대한 권한을 다르게 주려고 한다. (관리자만 다룰 수 있는 API가 있고, 일반 사용자도 다룰 수 있는 API가 있음) * 유저 등급이 1(어드민)과 10(일반회원) 2가지로 나누어져 있다고 가정 로직 순서 요청을 받으면 @Route Handler 실행 전 @UseGuards(JwtAuthGuard) 실행 JWTAuthGuard를 통해 토큰 검증 -> 토큰에 저장된 정보 반환 반환받은 정보를 Request 객체 내 user에 저장 @UseGuards(RolesGuards), @Admin(AdminGrade.Admin) 실행 RoleGuards 내의 권한을 확인하는 로직 실행 boolean 값을 반환 (false 일 경우 403 Forbidden 에러 반환) true일 경우 @Route ..
잘 정리되어 있는 블로그 https://sound-story.tistory.com/17 [NestJS] Authentication 구현 MSA(Micro Software Architecture) 구현 중 사용자 로그인과 관련하여 Authentication 부분을 구현해봅니다. 기존에 nest 개발하기 포스트에 이어서 작업한다고 생각하면 되겠습니다. https://sound-story.tistory.. sound-story.tistory.com

게시글을 등록하는 api를 만들던 중, 컴파일 과정에서는 에러가 없었는데 createPost를 실행하니 다음과 같은 에러 발생 import { Inject, Injectable } from '@nestjs/common'; import { Post } from 'src/_entity/post.entity'; import { Repository } from 'typeorm'; import { CreatePostDto } from './dto/create-post.dto'; @Injectable() export class PostService { constructor( @Inject('POST_REPOSITORY') private postRepository: Repository ) {} async create..

auth.service.ts 에서 다음과 같이 constructor를 추가했더니 에러 발생 import { Injectable } from '@nestjs/common'; import { JwtService } from '@nestjs/jwt'; import { LoginUserDto } from 'src/user/dto/login-user.dto'; import { UserService } from 'src/user/user.service'; @Injectable() export class AuthService { constructor( // *** 이 부분 private readonly jwtService: JwtService, private readonly userService: UserServic..
노마드코더 강의를 보면서 NsetJS 공부 중.. 프로젝트를 만들 때 controllers와 services, middlewares, libs로 폴더를 나누어 사용했었기 때문인지 NestJS의 아키텍처를 이해하는 데 좀 더 수월했다. 시작하기 // 설치 (최초 한 번) npm i -g @nestjs/cli // 프로젝트생성 nest new // 엔터 누르면 프로젝트명 입력하라고 함 nest new {폴더명} // 이렇게 바로 폴더명을 입력해도 됨 아키텍처 1) main.ts 필수 파일, 이름도 꼭 main.ts여야함 2) module 루트 역할, @Module 과 같은 데코레이터(@)를 사용(클래스에 함수 기능 추가) 3) controller express의 라우터 같은 존재로 url을 가져오고 함수를 ..