Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions src/api/auth/exchangeTempToken.ts

This file was deleted.

19 changes: 19 additions & 0 deletions src/api/auth/getToken.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { apiClient } from '../index';

export interface GetTokenRequest {
loginTokenKey: string; // 인가코드
}

export interface GetTokenResponse {
isSuccess: boolean;
code: number;
message: string;
data: {
token: string; // 토큰
};
}

export const getToken = async (data: GetTokenRequest): Promise<GetTokenResponse> => {
const response = await apiClient.post<GetTokenResponse>('/auth/token', data);
return response.data;
};
3 changes: 1 addition & 2 deletions src/api/auth/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export { setCookie } from './setCookie';
export { exchangeTempToken } from './exchangeTempToken';
export { getToken } from './getToken';
15 changes: 0 additions & 15 deletions src/api/auth/setCookie.ts

This file was deleted.

26 changes: 9 additions & 17 deletions src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,18 @@ export const apiClient = axios.create({
// const TEMP_ACCESS_TOKEN =
// 'eyJhbGciOiJIUzI1NiJ9.eyJ1c2VySWQiOjEsImlhdCI6MTc1NDM4MjY1MiwiZXhwIjoxNzU2OTc0NjUyfQ.BSGuoMWlrzc0oKgSJXHEycxdzzY9-e7gD4xh-wSDemc';

// Request 인터셉터: temp_token과 access_token 쿠키 처리
// Request 인터셉터: localStorage의 토큰을 헤더에 자동 추가
apiClient.interceptors.request.use(
config => {
// 쿠키에서 temp_token과 access_token 확인
const cookies = document.cookie.split(';');
const hasTempToken = cookies.some(cookie => cookie.trim().startsWith('temp_token='));
const hasAccessToken = cookies.some(cookie => cookie.trim().startsWith('access_token='));
// localStorage에서 토큰 확인
const authToken = localStorage.getItem('authToken');

if (hasAccessToken) {
// access_token이 있으면 정상 토큰 사용
console.log('✅ access_token 쿠키가 있어서 정상 토큰을 사용합니다.');
// access_token은 withCredentials: true로 자동 전송되므로 별도 헤더 설정 불필요
} else if (hasTempToken) {
// temp_token이 있으면 임시 토큰 사용
console.log('🔑 temp_token 쿠키가 있어서 임시 토큰을 사용합니다.');
// temp_token도 withCredentials: true로 자동 전송되므로 별도 헤더 설정 불필요
if (authToken) {
// 토큰이 있으면 Authorization 헤더에 추가
console.log('🔑 Authorization 헤더에 토큰 추가');
config.headers.Authorization = `Bearer ${authToken}`;
} else {
// 둘 다 없으면 인증 토큰 없음
console.log('❌ temp_token과 access_token 쿠키가 모두 없습니다.');
console.log('❌ localStorage에 토큰이 없습니다.');
}

return config;
Expand All @@ -50,8 +43,7 @@ apiClient.interceptors.response.use(
(response: AxiosResponse) => response,
(error: AxiosError) => {
if (error.response?.status === 401) {
// 인증 실패 시 로그인 페이지로 리다이렉트
// window.location.href = '/';
window.location.href = '/';
}
return Promise.reject(error);
},
Expand Down
48 changes: 48 additions & 0 deletions src/api/rooms/getSearchRooms.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { apiClient } from '../index';

export interface SearchRoomItem {
roomId: number;
bookImageUrl: string;
roomName: string;
memberCount: number;
recruitCount: number;
deadlineDate: string;
isPublic: boolean;
isFinalized?: boolean;
genre?: string;
}

export interface SearchRoomsResponse {
isSuccess: boolean;
code: number;
message: string;
data: {
roomList: SearchRoomItem[];
nextCursor: string | null;
isLast: boolean;
};
}

export const getSearchRooms = async (
keyword: string,
sort: 'deadline' | 'memberCount',
cursor?: string,
isFinalized: boolean = false,
category: string = '',
): Promise<SearchRoomsResponse> => {
try {
const params = new URLSearchParams();
params.append('keyword', keyword);
params.append('sort', sort);
params.append('isFinalized', String(isFinalized));
if (cursor) params.append('cursor', cursor);
if (category) params.append('category', category);

const url = `/rooms/search?${params.toString()}`;
const response = await apiClient.get<SearchRoomsResponse>(url);
return response.data;
} catch (error) {
console.error('방 검색 API 오류:', error);
throw error;
}
};
3 changes: 2 additions & 1 deletion src/api/users/postSignup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ export interface PostSignupRequest {
}

export interface PostSignupResponse {
success: boolean;
isSuccess: boolean;
code: number;
message: string;
data: {
userId: number;
accessToken: string; // 회원가입 완료 후 받는 access 토큰
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/group/CompletedGroupModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const CompletedGroupModal = ({ onClose }: CompletedGroupModalProps) => {
participants: room.memberCount,
maximumParticipants: room.recruitCount,
coverUrl: room.bookImageUrl,
deadLine: 0,
deadLine: '',
isOnGoing: false,
};
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/group/MyGroupBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface Group {
userName?: string;
progress?: number;
coverUrl: string;
deadLine?: number;
deadLine?: string;
genre?: string;
isOnGoing?: boolean;
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/group/MyGroupModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const MyGroupModal = ({ onClose }: MyGroupModalProps) => {
participants: room.memberCount,
maximumParticipants: room.recruitCount,
coverUrl: room.bookImageUrl,
deadLine: 0,
deadLine: '',
genre: '',
isOnGoing: room.type === 'playing' || room.type === 'playingAndRecruiting',
};
Expand Down
Loading