diff --git a/backend/src/auth/dto/user-data.dto.ts b/backend/src/auth/dto/user-data.dto.ts index ea9f7de..bfea330 100644 --- a/backend/src/auth/dto/user-data.dto.ts +++ b/backend/src/auth/dto/user-data.dto.ts @@ -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; +} diff --git a/backend/src/auth/entity/user.entity.ts b/backend/src/auth/entity/user.entity.ts index e7ba98e..02764c2 100644 --- a/backend/src/auth/entity/user.entity.ts +++ b/backend/src/auth/entity/user.entity.ts @@ -12,10 +12,7 @@ export class User { nickname: string; @Column() - character_name: string; - - @Column() - email: string; + characterName: string; @Column({ type: 'enum', diff --git a/backend/src/auth/jwt-auth.strategy.ts b/backend/src/auth/jwt-auth.strategy.ts index 6b2dacd..ab60f64 100644 --- a/backend/src/auth/jwt-auth.strategy.ts +++ b/backend/src/auth/jwt-auth.strategy.ts @@ -47,7 +47,7 @@ export class JwtStrategy2 extends PassportStrategy(Strategy, 'looseGuard') { } // db 참조 하지 않는 guard - async validate(): Promise { - return true; + async validate(payload: UserDataDto): Promise { + return payload; } } diff --git a/backend/src/auth/user.controller.ts b/backend/src/auth/user.controller.ts index 1dab866..cfdb304 100644 --- a/backend/src/auth/user.controller.ts +++ b/backend/src/auth/user.controller.ts @@ -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'; @@ -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'], }); } }