Skip to content

Commit

Permalink
✨ feat: AuthController 구현 및 AuthService에서 비밀번호 암호화 로직 추가(#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
jinddings committed Nov 6, 2024
1 parent 92c7549 commit bf295a6
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 13 deletions.
7 changes: 6 additions & 1 deletion BE/src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { Controller, Get, Body } from '@nestjs/common';
import { Controller, Post, Body } from '@nestjs/common';
import { AuthService } from './auth.service';
import { AuthCredentialsDto } from './dto/authCredentials.dto';

@Controller('auth')
export class AuthController {
constructor(private authService: AuthService) {}

@Post('/signup')
signUp(@Body() authCredentialsDto: AuthCredentialsDto) {
return this.authService.signUp(authCredentialsDto);
}
}
2 changes: 1 addition & 1 deletion BE/src/auth/auth.module.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { AuthController } from './auth.controller';
import { AuthService } from './auth.service';
import { TypeOrmModule } from '@nestjs/typeorm';
import { User } from './user.entity';
import { UserRepository } from './user.repository';

Expand Down
3 changes: 1 addition & 2 deletions BE/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { UserRepository } from './user.repository';
import { AuthCredentialsDto } from './dto/authCredentials.dto';
import { InjectRepository } from '@nestjs/typeorm';
import { bcrypt } from 'bcrypt';

@Injectable()
export class AuthService {
Expand Down
10 changes: 5 additions & 5 deletions BE/src/auth/user.entity.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { BaseEntity, Column, Entity, PrimaryColumn } from 'typeorm';
import { BaseEntity, Column, Entity, PrimaryGeneratedColumn } from 'typeorm';

@Entity()
export class User extends BaseEntity {
@PrimaryColumn()
@PrimaryGeneratedColumn()
id: number;

@Column()
Expand All @@ -11,9 +11,9 @@ export class User extends BaseEntity {
@Column()
password: string;

@Column()
@Column({ default: false })
tutorial: boolean;

@Column()
kakaoId: bigint;
@Column({ default: -1 })
kakaoId: number;
}
10 changes: 6 additions & 4 deletions BE/src/auth/user.repository.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Injectable } from '@nestjs/common';
import { InjectDataSource, InjectRepository } from '@nestjs/typeorm';
import { User } from './user.entity';
import { InjectDataSource } from '@nestjs/typeorm';
import { DataSource, Repository } from 'typeorm';
import * as bcrypt from 'bcrypt';
import { User } from './user.entity';
import { AuthCredentialsDto } from './dto/authCredentials.dto';

@Injectable()
Expand All @@ -12,8 +13,9 @@ export class UserRepository extends Repository<User> {

async registerUser(authCredentialsDto: AuthCredentialsDto) {
const { email, password } = authCredentialsDto;
const user = this.create({ email, password });

const salt: string = await bcrypt.genSalt();
const hashedPassword: string = await bcrypt.hash(password, salt);
const user = this.create({ email, password: hashedPassword });
await this.save(user);
}
}

0 comments on commit bf295a6

Please sign in to comment.