Conversation
|
ci 실패했는데 확인해주세요 |
| "private": true, | ||
| "dependencies": { | ||
| "@typegoose/typegoose": "^12.9.0", | ||
| "@types/jsonwebtoken": "^9.0.7", |
There was a problem hiding this comment.
types 는 dev dependencies 로 넣어주시면 됩니다
| public static async loadOrCreateUser(this: ReturnModelType<typeof User>, info: IUserInfo) { | ||
| let user = await this.findOne({ providerId: info.providerId }).exec() | ||
| if (!user) { | ||
| user = await this.create(info) | ||
| } | ||
| return user | ||
| } |
There was a problem hiding this comment.
도메인 단에서의 메소드 분리만 말씀하시는것이 맞으실까요?
There was a problem hiding this comment.
만약 분리를 하게 된다면, 클라이언트의 입장에서 카카오 로그인 버튼을 눌러서 실제 액세스 토큰을 받아 저희 서버로 요청을 보낼 때,
- 이전에 이미 회원가입이 된 유저인지
- 최초로 회원가입을 요청하는 유저인지
판단하는 로직을 따로 세워야합니다.
결국 사용자에게 추가적으로 요구하는 정보 (ex. 성별, 전화번호 등등..) 를 요구하는 것이 아니라면 API를 분리하는 것이 오히려 적절하지 않다고 저는 생각했습니다.
혹시 이에 대해서는 어떻게 생각하시나요? :)
There was a problem hiding this comment.
회원가입을 하는 과정에서 유저에게 서비스 동의를 받아야 합니다.
지금 로직은 유저의 동의 없이 유저 정보를 저희 db 에 저장하게 됩니다
최초 유저가 로그인 시도시 회원 가입이 안되있으면 에러를 주고 회원 가입 화면으로 보내는게 좋을것 같습니다
| @@ -0,0 +1,9 @@ | |||
| import { APIError } from '@/types/errors/error' | |||
|
|
|||
| export class HttpClientException extends APIError { | |||
There was a problem hiding this comment.
너무 제너럴한 이름인거 같아요.
kakao user info error 라고 해도 될것 같습니다
| export class Kakao { | ||
| public static async getUserInfo(payload: OAuthPayload) { | ||
| const { data } = await axios('https://kapi.kakao.com/v2/user/me', { | ||
| method: 'GET', | ||
| headers: { | ||
| Authorization: `Bearer ${payload.accessToken}`, | ||
| 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8', | ||
| }, | ||
| }).catch(e => { | ||
| throw new HttpClientException(e) | ||
| }) | ||
|
|
||
| return { | ||
| nickname: data.kakao_account.profile.nickname, | ||
| provider: 'KAKAO', | ||
| providerId: data.id, | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Oauth provider 코드는 각 Provider 별 파일로 관리하는게 좋을것 같아요
There was a problem hiding this comment.
넵 추후에 provider 추가시에 해당 부분도 같이 작업 진행해보겠습니다.
There was a problem hiding this comment.
추후 provier 작업을 다른 사람이 할수도 있으니 지금 하는게 좋을거 같아요
| @@ -0,0 +1,42 @@ | |||
| import axios from 'axios' | |||
There was a problem hiding this comment.
axios 말고 node-fetch 사용할게요
https://www.npmjs.com/package/node-fetch
There was a problem hiding this comment.
혹시 이유를 여쭤봐도 될까요? 저 또한 axios 와 node-fetch를 고민했어서 의견을 구하고 싶습니다 :)
There was a problem hiding this comment.
사실 큰 차이는 없습니다.
javascript 진영에서 fetch 를 택했으니 해당 라이브러리를 사용하는게 fe, be 통일과 앞으로의 지속성등의 관점에서
fetch 를 사용하는게 좋을거 같아요.
그리고 npm trends 에서도 node-fetch 가 미세하게 더 높습니다
| config() | ||
|
|
||
| export const { NODE_ENV, DB_URI, DB_NAME } = process.env | ||
| export const { NODE_ENV, DB_URI, DB_NAME, JWT_PRIVATE_KEY } = process.env |
There was a problem hiding this comment.
private key 는 비대칭키 알고리즘을 의미합니다.
저희는 대칭키로 쓸거니 SECRET 으로 표현하는게 맞을거 같아요
| export const { NODE_ENV, DB_URI, DB_NAME, JWT_PRIVATE_KEY } = process.env | |
| export const { NODE_ENV, DB_URI, DB_NAME, JWT_SECRET } = process.env |
|
|
||
| // todo: refactor this code blocks after introducing new oauth provider | ||
| // ==> split the code as service, and adding handler for controller logic | ||
| if (oauthPayload.provider === 'KAKAO') { |
There was a problem hiding this comment.
각 provider 별 필요한 정보를 얻어오는 middleware 와 해당 middleware 에서 얻은 정보로 jwt 를 만드는 handler 로 분리하면 될것 같습니다
There was a problem hiding this comment.
넵 express middleware를 활용해서 추후에 작업 진행해볼게요!
Co-authored-by: Kuwon Sebastian Na <laggu91@gmail.com>
Co-authored-by: Kuwon Sebastian Na <laggu91@gmail.com>
* @types/jsonwebtoken 패키지를 dev-dependencies로 이동
* change the name of exception which handles auth client
* provider 별 파일로 분리 * axios -> node-fetch 로 변경 * secret key 명칭 변경으로 인한 dotenv 관련 수정
* login, register 역할을 하는 API를 분리하였습니다
|
rebase 를 한건가요?? 코드가 꼬인거 같네요 |
실수로 리베이스를 잘못한 것 같아요 ㅜㅜ reflog로 다시 돌려서 리뷰 반영하였습니다! |
| "private": true, | ||
| "dependencies": { | ||
| "@typegoose/typegoose": "^12.9.0", | ||
| "axios": "^1.7.9", |
| public static async loadUser(this: ReturnModelType<typeof User>, info: IUserInfo) { | ||
| return await this.findOne({ providerId: info.providerId }).exec() | ||
| } |
There was a problem hiding this comment.
| public static async loadUser(this: ReturnModelType<typeof User>, info: IUserInfo) { | |
| return await this.findOne({ providerId: info.providerId }).exec() | |
| } | |
| public static async findByProviderId(this: ReturnModelType<typeof User>, providerId: string): Promise<User> { | |
| return await this.findOne({ providerId: providerId }).exec() | |
| } |
…` to `findByProviderId` and change its signiture
|
@laggu 제가 리베이스하면서 리뷰주신 내용을 하나 누락했던 것 같아요! 한번만 다시 확인해주시면 감사드리겠습니다 :) |
🚀 유저의 정보를 받아오는 쪽은 서버 사이드에서 수행하는 것이 적절하다고 판단하였습니다. 클라이언트단에서는 단순하게 얻은 액세스 토큰을 포함하여 fienmee server 로 보내주시면 됩니다.
성별, 나이 등..) 저희 페이지에서 새롭게 추가 정보를 입력받는식으로 구현한다면 좋을 것 같습니다. (비즈는 너무 투머치인 것 같아서요..)