Closed Blickwinkel1107 closed 2 months ago
Two things:
setupService
? Since this method is non-blocking, the loading could happen after the printingHi Jan. Thanks for reply.
onServiceConnected()
of service. Yeah it's non-blocking. I removed it btw.A more info about my scenario:
So in my application, there's a global supabaseClient variable to be accessed by other files.
And it seems when I access when service get connected (onServiceConnected) it works and doesn't need loadFromStorage
However when I am emitting a network request from a composable method with Launcheffect, supabase session returns null.
So it becomes:
1. I see tokens are non-null in onServiceConnected, where the whole service spins up.
2. I see tokens become null in launcheffect's http request method.
Btw, my application is a bit different, as I had some composable added to service.
Is it by default loaded from storage? I loaded manually just for make sure it's loaded.
Unless disabled in the config, yes. On Android it will load depending on lifecycle events to ensure that no expired sessions get loaded. You can try out two things:
Auth#sessionStatus
switches from LoadingFromStorage
to Authenticated
, NotAuthenticated
, etc.. sessionStatus
is a hot flow.Auth#awaitInitialization()
which basically does that, suspends the coroutine until the initialization is done.The initialization is not really noticeable in terms of time usage, but making requests before that or calling currentSessionOrNull
before that obviously fails.
Hi Jan.
When I called Auth#awaitInitialization()
, application got stuck at this method.
loadFromStorage
works as expected.
I'm not super sure if the issue relates to lifecycle management of composable views that added to windowManager.. I can find a time to have a minimum repro codes. Those Composable's lifecycleowner is set to the Service (as service has derived from LifecycleOwner)
If it got stuck, the loading never appeared. The implementation for the automatic loading can be viewed here. If this is related to a lifecycle issue, then maybe manual loading will be your best bet, but then I'd disable AuthConfig#enableLifecycleCallbacks
.
I can find a time to have a minimum repro codes.
If you want sure, not certain what exactly the problem is with the lifecycle.
Thanks so much for your help! Will post a repro tomorrow. (PDT timezone)
Also a QQ: should I have token stored to sharedPreference? Or I can rely on loadFromStorage
Also a QQ: should I have token stored to sharedPreference? Or I can rely on loadFromStorage
You can rely on loadFromStorage
. You don't have to worry about saving the session at all.
@Blickwinkel1107 Any update on this?
Closing due to inactivity, feel free to reopen.
General Info
Version(s)
2.5.2
Kotlin Target(s) and their respective versions
JVM8
What happened? (include your code)
I was trying to access accessToken/refreshToken in Service after user login in Activity. However the supabase client return null session. The issue varies in different phone OS. We found the issue on Harmony OS.
Steps To Reproduce (optional)
Relevant log output (optional)
No response