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: 10 additions & 13 deletions src/components/auth/LoginGuardDevPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import React from "react";
import { DevModeHandlers, CacheInfo } from "./LoginGuardTypes";
import { AuthTokens } from "@/utils/nativeBridge";
import { User } from "@/lib/api";
import { User, Store, PagedResult } from "@/lib/api";
import { Activity } from "@/hooks/useActivity";

interface LoginGuardDevPanelProps {
cacheInfo: CacheInfo;
Expand All @@ -15,9 +16,9 @@ interface LoginGuardDevPanelProps {
userInfoError: Error | null;
userInfo: User | undefined;
clearTokens: () => void;
stores: any[];
activities: any[] | undefined;
storesData: any;
stores: Store[];
activities: Activity[] | undefined;
storesData: PagedResult<Store> | undefined;
isAvailable: boolean;
devHandlers: DevModeHandlers;
}
Expand All @@ -44,8 +45,7 @@ export function LoginGuardDevPanel({
{/* 캐시 정보 */}
<div className="flex justify-between items-center mb-1">
<span>
캐시: {cacheInfo.count}개 |
{cacheInfo.isValid ? " 유효" : " 무효"} |
캐시: {cacheInfo.count}개 |{cacheInfo.isValid ? " 유효" : " 무효"} |
{cacheInfo.lastUpdate
? ` ${cacheInfo.lastUpdate.toLocaleTimeString()}`
: " 없음"}
Expand Down Expand Up @@ -154,9 +154,8 @@ export function LoginGuardDevPanel({
{/* 매장 및 활동 정보 */}
<div className="flex justify-between items-center">
<span>
매장: {stores.length ? `${stores.length}개` : "로딩..."} |
활동: {activities?.length || 0}개 | 총:{" "}
{storesData?.totalElements || 0}개
매장: {stores.length ? `${stores.length}개` : "로딩..."} | 활동:{" "}
{activities?.length || 0}개 | 총: {storesData?.totalElements || 0}개
</span>
</div>

Expand All @@ -165,9 +164,7 @@ export function LoginGuardDevPanel({
<span>
브릿지 상태: {isAvailable ? "✅ 연결됨" : "❌ 미연결"} |
NativeBridge:{" "}
{typeof window !== "undefined" && window.NativeBridge
? "✅"
: "❌"}{" "}
{typeof window !== "undefined" && window.NativeBridge ? "✅" : "❌"}{" "}
| iOS:{" "}
{typeof window !== "undefined" &&
window.webkit?.messageHandlers?.chalpu
Expand All @@ -178,4 +175,4 @@ export function LoginGuardDevPanel({
</div>
</div>
);
}
}
37 changes: 16 additions & 21 deletions src/hooks/useAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const useAuth = () => {
setTokens,
setLoading,
clearTokens,
initializeFromLocalStorage,
initialize,
} = useAuthStore();

// 토큰 초기화
Expand All @@ -23,21 +23,17 @@ export const useAuth = () => {

try {
// 로컬스토리지에서 accessToken 확인 및 자동 로그인
initializeFromLocalStorage();
initialize();
} catch (error) {
console.error("토큰 초기화 실패:", error);
clearTokens();
}

// 초기화 실패 시 안전장치: 3초 후 강제로 로딩 해제
setTimeout(() => {
setLoading(false);
}, 3000);
}, [
setLoading,
clearTokens,
initializeFromLocalStorage,
]);
}, [setLoading, clearTokens, initialize]);

// 토큰 갱신 (네이티브에서 처리하므로 단순히 로컬스토리지 재확인)
const refreshTokens = useCallback(async (): Promise<boolean> => {
Expand Down Expand Up @@ -101,36 +97,35 @@ export const useAuth = () => {

// 컴포넌트 마운트 시 토큰 초기화
useEffect(() => {
console.log('🔥 [useAuth] useEffect 시작, 현재 상태:', {
tokens: !!tokens,
isLoggedIn,
isLoading
console.log("🔥 [useAuth] useEffect 시작, 현재 상태:", {
tokens: !!tokens,
isLoggedIn,
isLoading,
});

// 즉시 초기화 시도
initializeTokens();

// fallback: 2초 후에도 여전히 로딩 중이면 강제 초기화
const fallbackTimer = setTimeout(() => {
const currentState = useAuthStore.getState();
console.log('🔥 [useAuth] Fallback 타이머 실행, 현재 상태:', {
console.log("🔥 [useAuth] Fallback 타이머 실행, 현재 상태:", {
tokens: !!currentState.tokens,
isLoggedIn: currentState.isLoggedIn,
isLoading: currentState.isLoading
isLoading: currentState.isLoading,
});

if (currentState.isLoading) {
console.log('🔥 [useAuth] 여전히 로딩 중 - 강제 초기화');
currentState.initializeFromLocalStorage();
console.log("🔥 [useAuth] 여전히 로딩 중 - 강제 초기화");
currentState.initialize();
}
}, 2000);

return () => {
clearTimeout(fallbackTimer);
};
}, [initializeTokens]);


return {
tokens,
isLoading,
Expand Down