Skip to content

Commit 438fb89

Browse files
authored
Merge pull request #267 from adamint/dev
3.6.01 - make getting pkce client in credential store synchronous
2 parents 4a42098 + 97cd457 commit 438fb89

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

src/androidMain/kotlin/com/adamratzman/spotify/auth/SpotifyDefaultCredentialStore.kt

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import com.adamratzman.spotify.models.Token
2020
import com.adamratzman.spotify.spotifyClientPkceApi
2121
import com.adamratzman.spotify.spotifyImplicitGrantApi
2222
import com.adamratzman.spotify.utils.logToConsole
23+
import kotlinx.coroutines.runBlocking
2324

2425
/**
2526
* Provided credential store for holding current Spotify token credentials, allowing you to easily store and retrieve
@@ -149,19 +150,21 @@ public class SpotifyDefaultCredentialStore(
149150
*
150151
* @param block Applied configuration to the [SpotifyImplicitGrantApi]
151152
*/
152-
public suspend fun getSpotifyClientPkceApi(block: ((SpotifyApiOptions).() -> Unit)? = null): SpotifyClientApi? {
153+
public fun getSpotifyClientPkceApi(block: ((SpotifyApiOptions).() -> Unit)? = null): SpotifyClientApi? {
153154
val token = spotifyToken ?: return null
154-
return spotifyClientPkceApi(
155-
clientId,
156-
redirectUri,
157-
SpotifyUserAuthorization(token = token),
158-
block ?: {}
159-
).build().apply {
160-
val previousAfterTokenRefresh = spotifyApiOptions.afterTokenRefresh
161-
spotifyApiOptions.afterTokenRefresh = {
162-
spotifyToken = this.token
163-
logToConsole("Refreshed Spotify PKCE token in credential store... $token")
164-
previousAfterTokenRefresh?.invoke(this)
155+
return runBlocking {
156+
spotifyClientPkceApi(
157+
clientId,
158+
redirectUri,
159+
SpotifyUserAuthorization(token = token),
160+
block ?: {}
161+
).build().apply {
162+
val previousAfterTokenRefresh = spotifyApiOptions.afterTokenRefresh
163+
spotifyApiOptions.afterTokenRefresh = {
164+
spotifyToken = this.token
165+
logToConsole("Refreshed Spotify PKCE token in credential store... $token")
166+
previousAfterTokenRefresh?.invoke(this)
167+
}
165168
}
166169
}
167170
}

0 commit comments

Comments
 (0)