문제:
구현을 다했는데 바디에 유저의 아이디와 비밀번호를 넣을 때
{
"username" : "test1@test.com",
"password" : "12345678"
}
으로 해야만 성공을 하는 데 "username" 부분을 원하는대로 수정하는 방법을 몰랐다.
검색을 해서 알아보니 super() 로 인해 발생한 현상 -> super 부분에서 원하는 대로 수정하여 해결
@Injectable()
export class LocalStrategy extends PassportStrategy(Strategy) {
constructor(private readonly authService: AuthService) {
super({
usernameField: 'email', // 여기서 'username' 대신 'email'을 사용하도록 설정
passwordField: 'password', // 필요하다면 여기도 바꾸는 것 가능
});
}
async validate(email: string, password: string): Promise<any> {
const user = await this.authService.validateUser(new ValidateUserRequestDto({ email, password }));
if (!user) {
throw new UnauthorizedException('Cannot find user');
}
return user;
}
}
'프로그래밍 > Nest.js' 카테고리의 다른 글
[ NestJS ] build 를 이용하여 배포하는 이유 (0) | 2024.06.02 |
---|---|
[ NestJS ] Configuration : Schema validation - Joi 예시 (0) | 2024.05.28 |
[ NestJS ] 생명주기에 따른 폴더구성 (0) | 2024.05.08 |
[ NestJS ] @Get, Promise.allSettled() 적용 (0) | 2024.05.06 |
[ Webstrom ] NestJS 디버깅하는 법 (0) | 2024.05.04 |