From c27841371a2530be731337b07283d4af83e6277d Mon Sep 17 00:00:00 2001 From: rudcks1237 Date: Sat, 30 Aug 2025 13:30:47 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20AppNav=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20?= =?UTF-8?q?=EC=83=81=ED=83=9C=EC=97=90=20=EB=94=B0=EB=A5=B8=20=EB=9D=BC?= =?UTF-8?q?=EC=9A=B0=ED=8C=85=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - DataStore 로딩 완료 후에만 라우팅 결정하도록 수정 - 로그인 정보가 있으면 바로 홈 화면으로, 없으면 바로 로그인 화면으로 이동 - 무한 로딩 문제 해결 및 중간 화면 전환 제거 --- .../com/shinhan/campung/navigation/AppNav.kt | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/android/campung/app/src/main/java/com/shinhan/campung/navigation/AppNav.kt b/android/campung/app/src/main/java/com/shinhan/campung/navigation/AppNav.kt index a781cc7..bda7bb8 100644 --- a/android/campung/app/src/main/java/com/shinhan/campung/navigation/AppNav.kt +++ b/android/campung/app/src/main/java/com/shinhan/campung/navigation/AppNav.kt @@ -55,11 +55,20 @@ fun AppNav( onNavControllerReady(navController) } - // 1) 상태 수집: 로그인 상태 + // 1) 로딩 상태 관리 + var isInitialLoading by remember { mutableStateOf(true) } val userId by authDataStore.userIdFlow.collectAsState(initial = null) - - // 2) userId가 아직 로드되지 않았으면 로딩 화면 표시 - if (userId == null) { + + // 2) 첫 번째 값이 도착하면 (null이든 실제값이든) 로딩 완료 + LaunchedEffect(Unit) { + val firstValue = authDataStore.userIdFlow.first() + isInitialLoading = false + android.util.Log.d("AppNav", "DataStore 로딩 완료 - userId: '$firstValue'") + } + + // 3) 초기 로딩 중이면 로딩 화면 표시 + if (isInitialLoading) { + android.util.Log.d("AppNav", "초기 로딩 중...") Box( modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center @@ -69,8 +78,13 @@ fun AppNav( return } - // 3) userId가 로드된 후 적절한 화면 결정 - val startRoute = if (userId?.isBlank() != false) Route.LOGIN else Route.HOME + // 4) 로딩 완료 후 적절한 화면 결정 + val startRoute = if (userId.isNullOrBlank()) Route.LOGIN else Route.HOME + + // 디버깅 로그 + LaunchedEffect(startRoute) { + android.util.Log.d("AppNav", "라우팅 결정: userId = '$userId', startRoute = '$startRoute'") + } Box(modifier = Modifier.fillMaxSize()) { // 항상 깔리는 기본 배경 (검은 잔상 방지)