:wave: — what’s the “correct” way to retrieve a JWT saved in a Proto DataStore in an API client? I h...
l
👋 — what’s the “correct” way to retrieve a JWT saved in a Proto DataStore in an API client? I have a DataSource which wraps the Flow from DataStore, but it’s not obvious how I can get the “latest token” from the flow —
last
on the flow blocks the app, and
collectLatest
gives me a closure not a return value, so I’m a little confused on what I do 😵‍💫 😵
Here’s the options I have so far — any guidance you can provide would be very very helpful! 🙇
Solved this by launching a new coroutine in
init
specifically to copy from the flow to an instance variable on the API client:
Copy code
init {
        scope.launch {
            apiPreferencesDataSource.apiData.collect { apiData ->
                Log.d("PartScanClient", "[INIT] getConfig: apiData='$apiData'")

                this@PartScanClient.token = apiData.token
            }
        }
    }
not confident this is the recommended way to get this done, but, it works