[NDD-79]: BE 재사용성 있는 코드 분리 && 활용성 확장 (1h / 1h) #21
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why
세 가지 이슈가 존재했다.
a. Authorization을 키로 헤더에서 문자열을 받아온다.
b. 이를 'Bearer '를 제외한 나머지만을 가져온다.
c. 해당 토큰을 활용한다.
위의 로직들을 반복적으로 추가해야 한다.
문서를 위한 로직들이 프로덕션 코드와 같이 있는것이 불편했다.
이를 위해, 해당 내용이 간소화되게 리펙토링해야겠다는 계획이 생겼다.
How
토큰을 통해서 최종적으로 Member객체를 가져오게 분리
토큰 반환 로직을 바로 사용할 수 있게 분리
옵션 생성을 함수로 처리할 수 있게 분리
Result
req.user로 strategy에서 validate의 반환값을 가져온다.
이전에 return한 req.user를 @useGuard(AuthGuard('jwt'))를 통해 활용할 수 있다.
위의 코드처럼 create~~~Option을 통해 swagger의 json을 축약시킬 수 있다.
Prize
Link
https://milk717.atlassian.net/browse/NDD-79