social 계정 재연동 로직 추가 .
This commit is contained in:
1 parent
3eedb8dc17
commit
29fdb7e65c
5 files changed
+106
-27
No files matched your search
+54
-24
@@ -25,6 +25,7 @@ import {
|
||||
SocialUploadRequest,
|
||||
SocialUploadResponse,
|
||||
SocialUploadStatusResponse,
|
||||
TokenExpiredErrorResponse,
|
||||
} from '../types/api';
|
||||
|
||||
const API_URL = import.meta.env.VITE_API_URL || 'http://40.82.133.44';
|
||||
@@ -695,6 +696,53 @@ export async function autocomplete(request: AutocompleteRequest): Promise<Crawli
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// Social OAuth TOKEN_EXPIRED 처리
|
||||
// ============================================
|
||||
|
||||
// YouTube 등 소셜 플랫폼 토큰 만료 에러 클래스
|
||||
export class TokenExpiredError extends Error {
|
||||
platform: string;
|
||||
reconnectUrl: string;
|
||||
|
||||
constructor(response: TokenExpiredErrorResponse) {
|
||||
super(response.detail);
|
||||
this.name = 'TokenExpiredError';
|
||||
this.platform = response.platform;
|
||||
this.reconnectUrl = response.reconnect_url;
|
||||
}
|
||||
}
|
||||
|
||||
// Social API 응답에서 TOKEN_EXPIRED 에러를 감지하고 처리
|
||||
async function handleSocialResponse(response: Response): Promise<void> {
|
||||
if (!response.ok) {
|
||||
const body = await response.json().catch(() => null);
|
||||
if (body && body.code === 'TOKEN_EXPIRED') {
|
||||
throw new TokenExpiredError(body as TokenExpiredErrorResponse);
|
||||
}
|
||||
throw new Error(body?.detail || `HTTP error! status: ${response.status}`);
|
||||
}
|
||||
}
|
||||
|
||||
// TOKEN_EXPIRED 발생 시 재연동 플로우 실행
|
||||
export async function handleSocialReconnect(reconnectUrl: string): Promise<void> {
|
||||
try {
|
||||
const response = await authenticatedFetch(`${API_URL}${reconnectUrl}`, {
|
||||
method: 'GET',
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`재연동 요청 실패: ${response.status}`);
|
||||
}
|
||||
|
||||
const data: { auth_url: string } = await response.json();
|
||||
window.location.href = data.auth_url;
|
||||
} catch (error) {
|
||||
console.error('[Social] 재연동 처리 실패:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// Social OAuth API (YouTube, Instagram, Facebook)
|
||||
// ============================================
|
||||
@@ -705,10 +753,7 @@ export async function getYouTubeConnectUrl(): Promise<YouTubeConnectResponse> {
|
||||
method: 'GET',
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
await handleSocialResponse(response);
|
||||
return response.json();
|
||||
}
|
||||
|
||||
@@ -718,10 +763,7 @@ export async function getSocialAccounts(): Promise<SocialAccountsResponse> {
|
||||
method: 'GET',
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
await handleSocialResponse(response);
|
||||
return response.json();
|
||||
}
|
||||
|
||||
@@ -731,10 +773,7 @@ export async function getSocialAccountByPlatform(platform: 'youtube' | 'instagra
|
||||
method: 'GET',
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
await handleSocialResponse(response);
|
||||
return response.json();
|
||||
}
|
||||
|
||||
@@ -744,10 +783,7 @@ export async function disconnectSocialAccount(accountId: number): Promise<Social
|
||||
method: 'DELETE',
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
await handleSocialResponse(response);
|
||||
return response.json();
|
||||
}
|
||||
|
||||
@@ -765,10 +801,7 @@ export async function uploadToSocial(request: SocialUploadRequest): Promise<Soci
|
||||
body: JSON.stringify(request),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
await handleSocialResponse(response);
|
||||
return response.json();
|
||||
}
|
||||
|
||||
@@ -778,10 +811,7 @@ export async function getUploadStatus(uploadId: string): Promise<SocialUploadSta
|
||||
method: 'GET',
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
await handleSocialResponse(response);
|
||||
return response.json();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user