# 401 global intercept to popup login form

**URL:** <https://discuss.kotlinlang.org/t/401-global-intercept-to-popup-login-form/29537>\
**Category:** Multiplatform\
**Created:** [November 17, 2024, 5:41pm UTC](https://discuss.kotlinlang.org/t/401-global-intercept-to-popup-login-form/29537 "2024-11-17T17:41:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![SamuelMarks](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/samuelmarks/32/10960_2.png) [@SamuelMarks](https://discuss.kotlinlang.org/u/SamuelMarks)\
**Post date:** [November 17, 2024, 5:41pm UTC](https://discuss.kotlinlang.org/t/401-global-intercept-to-popup-login-form/29537/1 "2024-11-17T17:41:04Z")

</div>

Specifically I don’t want the boring ‘open app’; ‘login’; ‘show authenticated flow’ approach. You should be able to get pretty deep into the application before it prompts you to auth.

I’ve got some pretty horrible code to do this per ‘Screen’ now:

```kt
@Composable
fun Screen1(viewModel: MySpecificViewModel,
            signInUpViewModel: SignInUpViewModel,
            uiState: MySpecificState) {
    val authUiState by signInUpViewModel.uiState.collectAsState()
    val globalGlobalGlobalStateLocal by globalGlobalState.collectAsState()

    if (globalGlobalGlobalStateLocal.token != null) {
        viewModel.postStuff(Stuff())
    } else {
        globalMutableStateFlow.update { it.copy(showAuth = true) }
    }
}

```

```kt
@Composable
fun Screen0(
  viewModel: MySpecificViewModel = viewModel { MySpecificViewModel() },
  signInUpViewModel: SignInUpViewModel = viewModel { SignInUpViewModel() }) {
    val globalGlobalGlobalStateLocal by globalGlobalState.collectAsState()
    val uiState by viewModel.uiState.collectAsState()

    if (globalGlobalGlobalStateLocal.showAuth) {
        val onDismissRequest = {
            globalMutableStateFlow.update { it.copy(showAuth = false) }
        }
        Dialog(
            onDismissRequest = onDismissRequest,
            properties = DialogProperties(
                dismissOnBackPress = false,
                dismissOnClickOutside = false
            )
        ) {
            AuthScreen(onDismissRequest = onDismissRequest)
        }
    } else {
        Screen0(viewModel = viewModel,
                signInUpViewModel = signInUpViewModel,
                uiState = uiState)
    }
}

```

I’m new to Kotlin Multiplatform and Compose broadly, but I’m thinking maybe a global error handling for ktor and figuring out how to use decompose [which I have integrated but don’t really know how to work with] to initiate an auth screen redirect from ktor error handling (I’m assuming some sort of event emission; so that the ktor code never needs to become `Composable`). Plenty of room for things to get confusing here as more auth providers are added, esp. wrt. ones which redirect back to the app (because then you state needs to be pushed around so that the initial auth-needed action is completed once auth is successful).

Any tips or sample projects would be appreciated.

---

<div class="post-metadata">

**Author:** ![Skater901](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/skater901/32/10163_2.png) [@Skater901](https://discuss.kotlinlang.org/u/Skater901)\
**Post date:** [November 19, 2024, 8:03am UTC](https://discuss.kotlinlang.org/t/401-global-intercept-to-popup-login-form/29537/2 "2024-11-19T08:03:32Z")

</div>

Maybe this is the wrong question, but why are you using Compose _with_ KTOR? Generally, you would use these two libraries for separate applications; make a GUI with Compose that makes web requests to a server, and the server can be written using KTOR. Are you making a desktop application? If so, you don’t need KTOR.
