diff --git a/be/src/auth/auth.service.ts b/be/src/auth/auth.service.ts index e4f16d5f..7aeabd18 100644 --- a/be/src/auth/auth.service.ts +++ b/be/src/auth/auth.service.ts @@ -13,7 +13,7 @@ export class AuthService { constructor( private userRepository: UserRepository, private jwtService: JwtService - ) {} + ) { } async NaverAuth(authorization: string) { if (!authorization) { throw new HttpException( @@ -42,7 +42,7 @@ export class AuthService { }); if (user) { - const payload = { nickName: user.nickName }; + const payload = { id: user.id }; const accessToken = this.jwtService.sign(payload); return accessToken; diff --git a/be/src/user/user.controller.ts b/be/src/user/user.controller.ts index fb2b3b73..a2d27cae 100644 --- a/be/src/user/user.controller.ts +++ b/be/src/user/user.controller.ts @@ -38,8 +38,8 @@ export class UserController { @ApiResponse({ status: 200, description: "정보 요청 성공" }) @ApiResponse({ status: 401, description: "인증 실패" }) @ApiResponse({ status: 400, description: "부적절한 요청" }) - async getUserInfo(@GetUser() tokenInfo: TokenInfo) { - return await this.userService.getUserInfo(tokenInfo); + async getUserInfo(@Param("nickname") nickname: UserInfoDto["nickName"]) { + return await this.userService.getUserInfo(nickname); } @Get() diff --git a/be/src/user/user.decorator.ts b/be/src/user/user.decorator.ts index 257f18f2..0d25f388 100644 --- a/be/src/user/user.decorator.ts +++ b/be/src/user/user.decorator.ts @@ -1,12 +1,12 @@ import { ExecutionContext, createParamDecorator } from "@nestjs/common"; export interface TokenInfo { - nickName: string; + id: number; } export const GetUser = createParamDecorator( - (data, ctx: ExecutionContext): TokenInfo => { - const req = ctx.switchToHttp().getRequest(); - return req.user; - } + (data, ctx: ExecutionContext): TokenInfo => { + const req = ctx.switchToHttp().getRequest(); + return req.user; + } ); diff --git a/be/src/user/user.repository.ts b/be/src/user/user.repository.ts index 04ddd1da..868db6b4 100644 --- a/be/src/user/user.repository.ts +++ b/be/src/user/user.repository.ts @@ -27,14 +27,14 @@ export class UserRepository extends Repository { }); return { isexist: user !== null }; } - async getMypageUserInfo(nickName: UserInfoDto["nickName"]) { + async getUserInfo(nickName: UserInfoDto["nickName"]) { const userInfo = await this.findOne({ select: ["nickName", "birthdate", "isMale", "region"], where: { nickName: nickName }, }); return { userInfo: userInfo }; } - async getMypageUserDetailInfo(nickName: UserInfoDto["nickName"]) { + async getMypageUserDetailInfo(id: number) { const userInfo = await this.findOne({ select: [ "nickName", @@ -44,14 +44,14 @@ export class UserRepository extends Repository { "provider", "email", ], - where: { nickName: nickName }, + where: { id: id }, }); return { userInfo: userInfo }; } - async deleteUserAccount(nickName: UserInfoDto["nickName"]) { + async deleteUserAccount(id: number) { const userInfo = await this.findOne({ select: ["id"], - where: { nickName: nickName }, + where: { id: id }, }); if (userInfo) { await this.update(userInfo.id, { deleted_at: new Date() }); @@ -60,10 +60,10 @@ export class UserRepository extends Repository { } return {}; } - async updateMypageUserInfo(nickName: UserInfoDto["nickName"], userInfoDto: UserInfoDto) { + async updateMypageUserInfo(id: number, userInfoDto: UserInfoDto) { const userInfo = await this.findOne({ select: ["id"], - where: { nickName: nickName }, + where: { id: id }, }); if (userInfo) { await this.update(userInfo.id, { diff --git a/be/src/user/user.service.ts b/be/src/user/user.service.ts index 7b0c5fb6..e16f2dd9 100644 --- a/be/src/user/user.service.ts +++ b/be/src/user/user.service.ts @@ -16,18 +16,18 @@ export class UserService { async getNickNameAvailability(nickName: UserInfoDto["nickName"]) { return await this.usersRepository.getNickNameAvailability(nickName); } - async getUserInfo(tokenInfo: TokenInfo) { - return await this.usersRepository.getMypageUserInfo(tokenInfo.nickName); + async getUserInfo(nickName: UserInfoDto["nickName"]) { + return await this.usersRepository.getUserInfo(nickName); } async getMypageUserDetailInfo(tokenInfo: TokenInfo) { return await this.usersRepository.getMypageUserDetailInfo( - tokenInfo.nickName + tokenInfo.id ); } async deleteUserAccount(tokenInfo: TokenInfo) { - return await this.usersRepository.deleteUserAccount(tokenInfo.nickName); + return await this.usersRepository.deleteUserAccount(tokenInfo.id); } async updateMypageUserInfo(tokenInfo: TokenInfo, userInfoDto: UserInfoDto) { - return await this.usersRepository.updateMypageUserInfo(tokenInfo.nickName, userInfoDto); + return await this.usersRepository.updateMypageUserInfo(tokenInfo.id, userInfoDto); } }