Hey! :wave: I’m not sure when this started, but I ...
# supabase-kt
n
Hey! 👋 I’m not sure when this started, but I found that in my JS app, the session is not restored when reloading the browser page. Big changes lately on my app were the migration to K2. It says
(Supabase-Auth) No session found
. On Android, the behaviour is the expected one. Anyway to debug this? Thanks!
j
This message gets logged if there was no session found: https://github.com/supabase-community/supabase-kt/blob/b39b2fcd0320be7d26a481d3dc9[…]src/commonMain/kotlin/io/github/jan/supabase/gotrue/AuthImpl.kt Is the session in the browser local storage?
n
It is certainly not… Let me debug the reason for that. I just found out that my coroutine might be getting cancelled too early.
Thanks 🙂
Ok, so here’s what was happening (simplified):
Copy code
//Class 1 (root app)
init {
    supabase.auth.sessionStatus
        .onEach { 
            when(it) {
                is SessionStatus.Authenticated -> navigateToPrivateSection()
                //...
            }
        }
}

//Class 2 (login component)
fun onLoginSubmit() {
    coroutineScope.launch {
        try {
            supabase.auth.signinWith(Email) {...}
        } catch (e: Exception) {
            Logger.e("Error logging in", e)
        }
    }
}
And the error was that class 2's coroutine was cancelled. So the auth stream emitted before the coroutine finished successfully storing the session in the storage. Changing the logic to navigate to the private section on class 2 when the coroutine finished did fix it. Is this expected? I mean, the stream emitting before storing.
Ah, I forgot to mention that class 2's coroutine scope gets disposed when navigating to the “private section”.
j
Is this expected? I mean, the stream emitting before storing.
Seems like it, but I agree the other way around would make more sense
n
It looks safer, yep. Do you want me to change that even if it’s so simple?
j
Yea, should be just a swap
n
Let me open a PR with the change 👍
👍 1