diff --git a/server/apps/api/src/auth/auth.controller.ts b/server/apps/api/src/auth/auth.controller.ts index 1ce9e73c..0987bd54 100644 --- a/server/apps/api/src/auth/auth.controller.ts +++ b/server/apps/api/src/auth/auth.controller.ts @@ -1,10 +1,11 @@ import { Body, Controller, Post } from '@nestjs/common'; import { AuthService } from './auth.service'; -import { SignInDto, SignUpDto } from './dto'; +import { SignUpDto } from './dto'; @Controller('api/user/auth') export class AuthController { constructor(private authService: AuthService) {} + @Post('signup') signup(@Body() dto: SignUpDto) { return this.authService.signup(dto); diff --git a/server/apps/api/src/auth/auth.service.ts b/server/apps/api/src/auth/auth.service.ts index c7cc4d05..80f3e5c5 100644 --- a/server/apps/api/src/auth/auth.service.ts +++ b/server/apps/api/src/auth/auth.service.ts @@ -1,7 +1,8 @@ -import { Injectable } from '@nestjs/common'; +import { ForbiddenException, Injectable } from '@nestjs/common'; import { SignUpDto } from './dto'; import * as argon from 'argon2'; import { UserRepository } from '@repository/user.repository'; +import { responseForm } from '@utils/responseForm'; @Injectable() export class AuthService { @@ -9,9 +10,14 @@ export class AuthService { async signup(dto: SignUpDto) { const hash = await argon.hash(dto.password); try { - const user = await this.userRepository.signup(dto); + await this.userRepository.create({ ...dto, password: hash }); } catch (error) { + if (error.name === 'MongoServerError' && error.code === 11000) + // 아이디 중복시 에러 + throw new ForbiddenException('아이디가 중복되었습니다.'); throw error; } + + return responseForm('200', '회원가입 성공!'); } }