Skip to content

Commit

Permalink
refactor : jwt 토큰 payload 데이터 nickname에서 id(번호)로 변경 #35
Browse files Browse the repository at this point in the history
  • Loading branch information
GeunH committed Nov 17, 2023
1 parent 7a85be0 commit ec05dbc
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions be/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class AuthService {
constructor(
private userRepository: UserRepository,
private jwtService: JwtService
) {}
) { }
async NaverAuth(authorization: string) {
if (!authorization) {
throw new HttpException(
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions be/src/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 5 additions & 5 deletions be/src/user/user.decorator.ts
Original file line number Diff line number Diff line change
@@ -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;
}
);
14 changes: 7 additions & 7 deletions be/src/user/user.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ export class UserRepository extends Repository<User> {
});
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",
Expand All @@ -44,14 +44,14 @@ export class UserRepository extends Repository<User> {
"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() });
Expand All @@ -60,10 +60,10 @@ export class UserRepository extends Repository<User> {
}
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, {
Expand Down
10 changes: 5 additions & 5 deletions be/src/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit ec05dbc

Please sign in to comment.