Skip to content

Commit

Permalink
feat: 회원가입 기능 구현
Browse files Browse the repository at this point in the history
- 비밀번호 hash로 변환
- DB 저장
- 중복시 예외처리
  • Loading branch information
soomanbaek authored and NaayoungKwon committed Nov 15, 2022
1 parent 7857529 commit 814d329
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
3 changes: 2 additions & 1 deletion server/apps/api/src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
10 changes: 8 additions & 2 deletions server/apps/api/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
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 {
constructor(private userRepository: UserRepository) {}
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', '회원가입 성공!');
}
}

0 comments on commit 814d329

Please sign in to comment.