Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()) {
// 항상 깔리는 기본 배경 (검은 잔상 방지)
Expand Down