Skip to content

Commit

Permalink
Merge pull request #66 from Boost-Coder/feature/nicknameDup-#63
Browse files Browse the repository at this point in the history
[#63] 닉네임 중복 체크
  • Loading branch information
koomin1227 authored Apr 17, 2024
2 parents 52d4625 + 828b602 commit 1b6b538
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Entity/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class User {
@Column({
length: 30,
nullable: true,
unique: true,
})
nickname: string;

Expand Down
8 changes: 8 additions & 0 deletions src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,16 @@ export class AuthController {
return await this.authService.checkSejongStudent(body, userId);
}


@Post('checkNickname')
@UseGuards(JwtAuthGuard)
public async checkNickname(@Body('nickname') nickname: string) {
return await this.authService.checkNicknameDuplicate(nickname);
}

@Post('refresh')
public refreshTokens(@Body('refreshToken') refreshToken: string) {
return this.authService.sendTokens(refreshToken);

}
}
17 changes: 16 additions & 1 deletion src/auth/auth.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { Injectable, UnauthorizedException } from '@nestjs/common';
import {
ConflictException,
Injectable,
UnauthorizedException,
} from '@nestjs/common';
import { AppleLoginDto } from './appleLogin.dto';
import * as jwt from 'jsonwebtoken';
import * as jwksClient from 'jwks-rsa';
Expand Down Expand Up @@ -144,6 +148,17 @@ export class AuthService {
}
}


public async checkNicknameDuplicate(nickname: string) {
const isExist = await this.userService.checkNicknameDuplicate(nickname);

if (isExist) {
throw new ConflictException('중복되는 닉네임입니다');
} else {
return { isDuplicate: false };
}
}

public sendTokens(refreshToken: string) {
const payload = this.validateRefreshToken(refreshToken);

Expand Down
4 changes: 4 additions & 0 deletions src/user/user.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ export class UserRepository extends BaseRepository {
return await this.repository.findOneBy({ userId: userId });
}

async findOneByNickname(nickname: string) {
return await this.repository.findOneBy({ nickname: nickname });
}

async findOneWithStats(userId: string) {
return await this.repository.findOne({
where: { userId: userId },
Expand Down
4 changes: 4 additions & 0 deletions src/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,8 @@ export class UserService {
const uuid: string = uuidv4();
return uuid.slice(0, 8);
}

async checkNicknameDuplicate(nickname: string) {
return await this.userRepository.findOneByNickname(nickname);
}
}

0 comments on commit 1b6b538

Please sign in to comment.