Skip to content

Commit

Permalink
use v2 access token for serp promo cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
lmac012 committed Nov 21, 2024
1 parent c4b6119 commit a9ff626
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ internal class RealAuthRepository constructor(
override suspend fun setAccessTokenV2(accessToken: AccessToken?) = withContext(dispatcherProvider.io()) {
subscriptionsDataStore.accessTokenV2 = accessToken?.jwt
subscriptionsDataStore.accessTokenV2ExpiresAt = accessToken?.expiresAt
updateSerpPromoCookie()
}

override suspend fun getAccessTokenV2(): AccessToken? {
Expand Down Expand Up @@ -123,7 +124,7 @@ internal class RealAuthRepository constructor(

override suspend fun setAccessToken(accessToken: String?) = withContext(dispatcherProvider.io()) {
subscriptionsDataStore.accessToken = accessToken
serpPromo.injectCookie(accessToken)
updateSerpPromoCookie()
}

override suspend fun setAuthToken(authToken: String?) = withContext(dispatcherProvider.io()) {
Expand Down Expand Up @@ -189,6 +190,11 @@ internal class RealAuthRepository constructor(
override suspend fun canSupportEncryption(): Boolean = withContext(dispatcherProvider.io()) {
subscriptionsDataStore.canUseEncryption()
}

private suspend fun updateSerpPromoCookie() {
val accessToken = subscriptionsDataStore.run { accessTokenV2 ?: accessToken }
serpPromo.injectCookie(accessToken)
}
}

data class AccessToken(
Expand Down

0 comments on commit a9ff626

Please sign in to comment.