Skip to content

Commit

Permalink
refactor(#10): 커스텀 데코레이터 auth 컨트롤러에 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
NicoDora committed Nov 2, 2023
1 parent dd7e019 commit 09e73ba
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 49 deletions.
2 changes: 1 addition & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { ScheduleModule } from '@nestjs/schedule';
UserModule,
TypeOrmModule.forRoot({
...TypeORMconfig, // TypeORM 설정 객체 확장
synchronize: true, // DB 동기화 여부 설정
synchronize: false, // DB 동기화 여부 설정
}),
// TypeOrmModule.forFeature([Image]),
ConfigModule.forRoot({
Expand Down
3 changes: 1 addition & 2 deletions src/auth/auth.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ import { S3Service } from 'src/common/s3/s3.service';
import { UserImageRepository } from 'src/users/repositories/user-image.repository';
import { TokenRepository } from './repositories/token.repository';
import { TokenService } from './services/token.service';
import { JwtStrategy } from 'src/config/strategis/jwt-access-token.strategy';

@Module({
imports: [],
exports: [TokenService, TokenRepository],
controllers: [AuthController],
providers: [AuthService, TokenService, UserRepository, UserImageRepository, TokenRepository, S3Service, JwtStrategy],
providers: [AuthService, TokenService, UserRepository, UserImageRepository, TokenRepository, S3Service],
})
export class AuthModule {}
18 changes: 8 additions & 10 deletions src/auth/controllers/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ export class AuthController {
}

@ApiKakaoLogout()
@UseGuards(JwtAccessTokenGuard)
@Post('kakao/logout')
async kakaoLogout(@Headers('access_token') accessToken: string) {
const userId = await this.tokenService.decodeToken(accessToken);
async kakaoLogout(@GetUserId() userId: number) {
const { socialAccessToken, socialRefreshToken } =
await this.tokenService.getUserTokens(userId);
await this.tokenService.deleteTokens(userId);
Expand All @@ -102,9 +102,9 @@ export class AuthController {
}

@ApiKakaoUnlink()
@UseGuards(JwtAccessTokenGuard)
@Post('kakao/unlink')
async kakaoUnlink(@Headers('access_token') accessToken: string) {
const userId = await this.tokenService.decodeToken(accessToken);
async kakaoUnlink(@GetUserId() userId: number) {
const { socialAccessToken, socialRefreshToken } =
await this.tokenService.getUserTokens(userId);
await this.tokenService.deleteTokens(userId);
Expand All @@ -118,15 +118,13 @@ export class AuthController {
@UseGuards(JwtAccessTokenGuard)
@Post('naver/logout')
async naverLogout(@GetUserId() userId: number) {
console.log('userId: ', userId);

return await this.tokenService.deleteTokens(userId);
}

@ApiNaverUnlink()
@UseGuards(JwtAccessTokenGuard)
@Post('naver/unlink')
async naverUnlink(@Headers('access_token') accessToken: string) {
const userId = await this.tokenService.decodeToken(accessToken);
async naverUnlink(@GetUserId() userId: number) {
const { socialAccessToken, socialRefreshToken } =
await this.tokenService.getUserTokens(userId);
await this.tokenService.deleteTokens(userId);
Expand All @@ -137,9 +135,9 @@ export class AuthController {
}

@ApiDeleteAccount()
@UseGuards(JwtAccessTokenGuard)
@Delete('account')
async accountDelete(@Headers('access_token') accessToken: string) {
const userId = await this.tokenService.decodeToken(accessToken);
async accountDelete(@GetUserId() userId: number) {
await this.s3Service.deleteImagesWithPrefix(userId + '_');
return await this.authService.accountDelete(userId);
}
Expand Down
4 changes: 1 addition & 3 deletions src/boards/entities/board-image.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ export class BoardImage {
@PrimaryGeneratedColumn()
id: number;

@ManyToOne(() => Board, (board) => board.boardImages, {
onDelete: 'CASCADE',
})
@ManyToOne(() => Board, (board) => board.boardImages)
@JoinColumn({ name: 'board_id' })
board: Board;

Expand Down
5 changes: 3 additions & 2 deletions src/boards/entities/board.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export class Board {
@Column('varchar')
head: string;

@Column()
@Index({ fulltext: true })
@Column('text')
body: string;

@Column()
Expand All @@ -53,4 +54,4 @@ export class Board {

@UpdateDateColumn({ name: 'updated_at' })
updateAt: Date;
}
}
1 change: 0 additions & 1 deletion src/config/guards/jwt-access-token.guard.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ExecutionContext, Injectable } from "@nestjs/common";
import { AuthGuard } from "@nestjs/passport";
import { TokenService } from "src/auth/services/token.service";

@Injectable()
Expand Down
30 changes: 0 additions & 30 deletions src/config/strategis/jwt-access-token.strategy.ts

This file was deleted.

0 comments on commit 09e73ba

Please sign in to comment.