Skip to content

Conversation

@blu3fishez
Copy link
Collaborator

Note

한꺼번에 많은 PR을 올리지 않도록 분리하였습니다. (제가 코드를 빨리치다보니 이걸 좀 분리하고싶은데 고민이네요.)
#260
#261
을 먼저 확인해주세요. 이 PR과 연관되어있어서 이 PR 이 머지되면 저곳도 머지 됩니다.

관련 이슈 번호

  • 작성자: 김찬우
  • 작성 날짜: 2024.11.28

✅ 체크리스트

  • 코드가 정상적으로 작동하는지 확인했습니다.
  • 주요 변경사항에 대한 설명을 작성했습니다.
  • 코드 스타일 가이드에 따라 코드를 작성했습니다.

🧩 작업 내용

  • 로그인 회원가입 기능을 위한 DTO 추가
  • 로그인 기능을 위한 passport 전략 추가
  • 쿠키 설정 시 secure 값을 production 일때만 되도록 허용

📝 작업 상세 내역

로그인 회원가입 기능을 위한 DTO 추가

  • 회원가입을 위한 DTO 추가
  • 로그인을 위한 DTO 추가
  • DTO가 좀 여러개 변경사항을 확인해보셔야할 거에요.
  • 저한테 말 거시면 상세히 알려드리겠습니다.

로그인 기능을 위한 passport 전략 추가

  • 실제 인증은 auth 에서 합니다.
  • 유저는 유저 정보 자체를 다루는데 집중하고, 해야할 것 같았습니다.
  • 패스워드 해시 생성도 인증쪽에서 다루도록 바꾸었습니다.
import { Strategy } from "passport-local";
import { PassportStrategy } from "@nestjs/passport";
import { Injectable, UnauthorizedException } from "@nestjs/common";
import { JwtService } from "@/auth/jwt/jwt.service";
import { AuthService } from "@/auth/auth.service";

@Injectable()
export class LocalStrategy extends PassportStrategy(Strategy) {
    constructor(
        private readonly authService: AuthService,
        private readonly jwtService: JwtService
    ) {
        super({
            usernameField: "userId",
            passwordField: "password",
        });
    }

    async validate(username: string, password: string): Promise<any> {
        const user = await this.authService.getUserByLocal(username, password);

        if (!user) throw new UnauthorizedException("Invalid User login!");
        const token = await this.jwtService.createJwtToken(user);

        return {
            jwtToken: token,
        };
    }
}
  • 보시는 것처럼 API 명세도 맞추어서 적용했습니다

쿠키 설정 시 secure 값을 production 일때만 되도록 허용

import "dotenv/config";

export const setCookieConfig = {
    httpOnly: true,
    secure: process.env.NODE_ENV === "production",
};

📌 테스트 및 검증 결과

  • POSTMAN으로 요청했습니다.
  • 실제 데이터베이스에 회원가입은 잘 됩니다!
  • 로그인은 POSTMAN으로 확인했습니다.

💬 다음 작업 또는 논의 사항

  • 기능 개발은 여기까지가 끝입니다. (안심하세요..)
  • 스터디 세션 hex 코드로 서렂ㅇ해서 길이가 길어서 불편했을 텐데, 그걸 base64 기반으로 인코딩으로 바꿨는데, 다음 PR 에 올리겠습니다.

🐥 리뷰 받고 싶은 포인트

  • 연관성이 있는 긴 작업을 할 때 어떻게 해야할지 참 고민입니다.

- 비밀번호 변경
- 유저 메타 데이터 업데이트 기능
- 로컬로 로그인할 수 있도록 하는 회원가입 기능
- 아이디로 엔티티 검색 가능.
- 추후 인덱싱해야함
- 1초는 1000 밀리 세컨드 ..
- 현재 시간을 더하는게 아니라, 만료 전체 시간을 더해야했음
- jwt service 설정에 만료시간 설정이 없어서 삭제
- `인증`까지만 범위 설정을 어떻게 할지 고민을 많이 했음
- 인증에 성공했다면, 토큰을 받아오도록 통일해야하지 않을까? 라는 생각을 하게 됨
- 그렇게 전략 패턴별로 토큰을 반환하도록 통일함
- GithubProfile 이라는 정보도 나중에 삭제할 예정
- 회원가입을 위한 DTO 추가
- 로그인을 위한 DTO 추가
- 로컬 로그인 시 http 에서도 테스트할 수 있도록 허용
Copy link
Member

@yiseungyun yiseungyun left a comment

Choose a reason for hiding this comment

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

매직 남바를 사용하다니 고수의 냄새가 납니다.
MZTM 드립니다. 다봉. 👍

Copy link
Collaborator

@twalla26 twalla26 left a comment

Choose a reason for hiding this comment

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

LGTM!!!

Copy link
Member

@ShipFriend0516 ShipFriend0516 left a comment

Choose a reason for hiding this comment

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

로컬 로그인 막아뒀었는데 봉인 해제할 때가 되었군요.. 고생하셨습니다

@ShipFriend0516 ShipFriend0516 merged commit 6d2768c into boostcampwm-2024:dev Nov 28, 2024
@blu3fishez blu3fishez deleted the feature/local-login branch September 1, 2025 06:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants