Skip to content

Commit

Permalink
Chore: #228 MSW에서 JWT 더미 데이터 사용한 코드 일괄 삭제
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoonyesol committed Oct 17, 2024
1 parent 9e9c017 commit 5aa5f0b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 49 deletions.
38 changes: 7 additions & 31 deletions src/mocks/services/authServiceHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,18 +228,10 @@ const authServiceHandler = [
return HttpResponse.json({ message: '리프레시 토큰이 만료되었습니다.' }, { status: 401 });
}

let newAccessToken;

// ToDo: 추후 삭제
if (accessToken === JWT_TOKEN_DUMMY) {
newAccessToken = 'newMockedAccessToken';
} else {
// 토큰에서 userId 추출하도록 수정
const userId = convertTokenToUserId(accessToken);
if (!userId) return new HttpResponse(null, { status: 401 });
const userId = convertTokenToUserId(accessToken);
if (!userId) return new HttpResponse(null, { status: 401 });

newAccessToken = generateDummyToken(userId);
}
const newAccessToken = generateDummyToken(userId);

// 액세스 토큰 갱신
return new HttpResponse(null, {
Expand All @@ -259,16 +251,8 @@ const authServiceHandler = [

if (!accessToken) return new HttpResponse(null, { status: 401 });

let userId;
// ToDo: 추후 삭제
if (accessToken === JWT_TOKEN_DUMMY) {
const payload = JWT_TOKEN_DUMMY.split('.')[1];
userId = Number(payload.replace('mocked-payload-', ''));
} else {
// 토큰에서 userId 추출
userId = convertTokenToUserId(accessToken);
if (!userId) return new HttpResponse(null, { status: 401 });
}
const userId = convertTokenToUserId(accessToken);
if (!userId) return new HttpResponse(null, { status: 401 });

const foundUser = USER_DUMMY.find((user) => user.userId === userId);
if (!foundUser) return new HttpResponse(null, { status: 404 });
Expand Down Expand Up @@ -385,16 +369,8 @@ const authServiceHandler = [
const accessToken = request.headers.get('Authorization');
if (!accessToken) return HttpResponse.json({ message: '인증 정보가 존재하지 않습니다.' }, { status: 401 });

let userId;
// ToDo: 추후 삭제
if (accessToken === JWT_TOKEN_DUMMY) {
const payload = JWT_TOKEN_DUMMY.split('.')[1];
userId = Number(payload.replace('mocked-payload-', ''));
} else {
// 토큰에서 userId 추출
userId = convertTokenToUserId(accessToken);
if (!userId) return new HttpResponse(null, { status: 401 });
}
const userId = convertTokenToUserId(accessToken);
if (!userId) return new HttpResponse(null, { status: 401 });

const existingUser = USER_DUMMY.find((user) => user.userId === Number(userId));
if (!existingUser) return HttpResponse.json({ message: '해당 사용자를 찾을 수 없습니다.' }, { status: 404 });
Expand Down
21 changes: 3 additions & 18 deletions src/mocks/services/userServiceHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,8 @@ const userServiceHandler = [

const { nickname, bio } = (await request.json()) as EditUserInfoForm;

let userId;
// ToDo: 추후 삭제
if (accessToken === JWT_TOKEN_DUMMY) {
const payload = JWT_TOKEN_DUMMY.split('.')[1];
userId = Number(payload.replace('mocked-payload-', ''));
} else {
// 토큰에서 userId 추출
userId = convertTokenToUserId(accessToken);
}
// 토큰에서 userId 추출
const userId = convertTokenToUserId(accessToken);

const userIndex = userId ? USER_DUMMY.findIndex((user) => user.userId === userId) : -1;

Expand Down Expand Up @@ -58,15 +51,7 @@ const userServiceHandler = [

const { links } = (await request.json()) as EditUserLinksForm;

let userId;
// ToDo: 추후 삭제
if (accessToken === JWT_TOKEN_DUMMY) {
const payload = JWT_TOKEN_DUMMY.split('.')[1];
userId = Number(payload.replace('mocked-payload-', ''));
} else {
// 토큰에서 userId 추출
userId = convertTokenToUserId(accessToken);
}
const userId = convertTokenToUserId(accessToken);

const userIndex = userId ? USER_DUMMY.findIndex((user) => user.userId === userId) : -1;

Expand Down

0 comments on commit 5aa5f0b

Please sign in to comment.