Skip to content

[Feat] 9주차 미션_누누 - #65

Open
JeongCW0522 wants to merge 7 commits into
nunufrom
week9-nunu
Open

[Feat] 9주차 미션_누누#65
JeongCW0522 wants to merge 7 commits into
nunufrom
week9-nunu

Conversation

@JeongCW0522

@JeongCW0522 JeongCW0522 commented May 25, 2026

Copy link
Copy Markdown
Collaborator

📂 관련 이슈


🛠️ 작업 사항

  • 기존에 사용자의 정보를 하드 코딩 했던 부분들이 있다면 수정
    • userId = 1const user = req.user as User 수정
    • @Request 데코레이션 추가
  • Google 로그인 후 자신의 정보를 수정하는 API 구현
  • 인증 시스템(JWT) 을 그동안 만들었던 기존 API들에 적용
    • auth.middleware.tsexpressAuthentication함수 추가
    • tsoa.json"authenticationModule": "./src/middlewares/auth.middleware.ts" 추가
    • userId를 필요로 하던 각 컨트롤러에 @Security("jwt") 데코레이션 추가
  • Google 로그인 외에 다른 소셜 로그인을 하나 더 연동 (카카오 로그인)

📸 관련 이미지 (스크린샷 또는 동영상)

정보 수정 API

image

로그인 보호

image

💬 기타 설명

💡 추가적으로 공유할 내용이나 리뷰어에게 전달할 사항이 있다면 작성해 주세요.

@JeongCW0522
JeongCW0522 requested a review from wldmsdl7 May 25, 2026 03:09
@JeongCW0522 JeongCW0522 self-assigned this May 25, 2026
@JeongCW0522 JeongCW0522 added ✨Feature 새로운 기능 추가 📡 API API 관련 작업 🔨 Refactor 기능은 그대로인데 코드 구조 개선 labels May 25, 2026

@wldmsdl7 wldmsdl7 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

전체적으로 워크북 기반으로 잘 구현해주신 것 같아 !
다만 워크북에서는 tsoa 기반 인증 구조를 사용하고 있는데,
현재 일부 API들은 app.get으로 직접 라우터를 등록하고 있어 인증 및 라우팅 방식이 조금 혼재된 것 같아.

@Security("jwt")와 Controller 기반 구조로 통일해주면 인증 흐름과 Swagger 문서화까지 더 일관성 있게 가져갈 수 있을 것 같아 ~

어려웠던 인증 로직일 수 있는데, 잘해준 것 같아 ~ 수고했어 !

Comment thread nunu/week9/src/index.ts

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이전 주차에서 tsoa를 적용하며 라우터들을 Controller 단으로 분리해두었는데,
현재 일부 API들은 tsoa를 사용하지 않고 app.get으로 직접 라우터를 등록하고 있네 .. !!

워크북 코드를 기반으로 작성했더라도, 라우팅 방식은 하나로 통일해서 정리해두는 게 좋아 ~

Comment on lines +49 to +67
let user = await prisma.user.findFirst({
where: {
email,
},
});

if (!user) {
user = await prisma.user.create({
data: {
email,
password: "GOOGLE_LOGIN_USER",
name: profile.displayName,
gender: "MALE",
birthDate: new Date("1970-01-01"),
address: "추후 수정",
phoneNumber: null,
},
});
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

현재 googleVerify 내부에서 사용자 조회 및 생성 로직가지 함께 처리하고 있어서 Strategy 계층이 인증 역할 외의 책임도 함께 가지고 잇는 것 같아.

지금 구조도 동작에는 문제가 없지만, OAuth Strategy에서는 인증 결과만 전달하고, 실제 회원 조회/생성 로직은 Service 단으로 분리해주면 계층 역할이 더 명확해질 것 같아.

특히 현재는 prisma.user.findFirst와 같은 함수까지 호출하고 있어 DB 접근 책임까지 함께 포함되어 있는 것 같아.

Comment on lines +109 to +127
let user = await prisma.user.findFirst({
where: {
email,
},
});

if (!user) {
user = await prisma.user.create({
data: {
email,
password: "KAKAO_LOGIN_USER",
name: name,
gender: "MALE",
birthDate: new Date("1970-01-01"),
address: "추후 수정",
phoneNumber: null,
},
});
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기도 똑같이 분리해주는 게 좋을 것 같아 !

const name = profile.displayName || "카카오유저";

if (!email) {
throw new Error("카카오 계정 이메일이 없습니다.");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기도 커스텀 에러를 만들어 전역으로 에러 핸들링을 해주는 게 좋지 않을까 ?

Comment on lines +166 to +172
async (payload, done) => {
try {
const user = await prisma.user.findFirst({
where: {
id: BigInt(payload.id),
},
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기도 ~~

Comment thread nunu/week9/src/index.ts
Comment on lines +107 to +110
const isLogin = passport.authenticate("jwt", { session: false });

app.get("/mypage", isLogin, (req, res) => {
const user = req.user as User;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

지금처럼 Express 라우터에 직접 인증 미들웨어를 붙이는 방식보다는 tsoa 컨트롤러에서 @Security("jwt")를 사용하는 방식이 더 좋을 것 같아 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

📡 API API 관련 작업 ✨Feature 새로운 기능 추가 🔨 Refactor 기능은 그대로인데 코드 구조 개선

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants