Skip to content

Commit

Permalink
[feat] #4 회원가입 API 수정 및 pipe 추가
Browse files Browse the repository at this point in the history
- Validation pipe로 signupData를 유효성 검사
- signUp API 요청시 signupData 라는 객체 필수
- signupData = { nickname , characterName }
  • Loading branch information
comeintostout committed Nov 19, 2022
1 parent fb46351 commit ebe4b54
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 12 deletions.
27 changes: 26 additions & 1 deletion backend/src/auth/dto/user-data.dto.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,43 @@
import { IsString } from 'class-validator';
import {
IsNotEmpty,
IsString,
Matches,
MaxLength,
MinLength,
} from 'class-validator';
import { socialPlatform } from '../user.enum';

export class UserDataDto {
@IsNotEmpty()
@IsString()
id: string;

@IsNotEmpty()
@IsString()
social: socialPlatform;
}

export class UserDataFromSocialDto {
@IsNotEmpty()
@IsString()
id: string;

@IsNotEmpty()
@IsString()
profileImg: string;
}

export class signupDataDto {
@IsNotEmpty()
@IsString()
@MinLength(4)
@MaxLength(12)
@Matches(/^[a-zA-z0-9ㄱ-ㅎㅏ-ㅣ가-힣 ]*$/, {
message: '특수문자는 불가합니다.',
})
nickname: string;

@IsNotEmpty()
@IsString()
characterName: string;
}
5 changes: 1 addition & 4 deletions backend/src/auth/entity/user.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ export class User {
nickname: string;

@Column()
character_name: string;

@Column()
email: string;
characterName: string;

@Column({
type: 'enum',
Expand Down
4 changes: 2 additions & 2 deletions backend/src/auth/jwt-auth.strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class JwtStrategy2 extends PassportStrategy(Strategy, 'looseGuard') {
}

// db 참조 하지 않는 guard
async validate(): Promise<boolean> {
return true;
async validate(payload: UserDataDto): Promise<UserDataDto> {
return payload;
}
}
17 changes: 12 additions & 5 deletions backend/src/auth/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ import {
Param,
Post,
Query,
Req,
Res,
UseGuards,
ValidationPipe,
} from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { Response } from 'express';
import { AuthService } from 'src/auth/auth.service';
import { signupDataDto, UserDataDto } from './dto/user-data.dto';
import { socialPlatformValidationPipe } from './pipes/social-platform.pipe';
import { socialPlatform } from './user.enum';
import { UserService } from './user.service';
Expand Down Expand Up @@ -70,13 +73,17 @@ export class UserController {

@Post()
@UseGuards(AuthGuard('looseGuard'))
signUp(@Body() signupData: object) {
// jwt안에 값 추출로직
signUp(
@Body('signupData', ValidationPipe) signupData: signupDataDto,
@Req() req: any
) {
const { id, social }: UserDataDto = req.user;
// body안에 nickname, characterName FE에 전송 요청
this.userService.createUser({
id: signupData['id'],
id,
social,
nickname: signupData['nickname'],
character_name: signupData['character_name'],
social: signupData['social'],
characterName: signupData['characterName'],
});
}
}

0 comments on commit ebe4b54

Please sign in to comment.