Skip to content
This repository was archived by the owner on Feb 24, 2025. It is now read-only.

Commit 02a9657

Browse files
authored
Only attempt to refresh auth token when user is authenticated (#3721)
Task/Issue URL: https://app.asana.com/0/414709148257752/1208966018277167/f **Description**: Following [Increase of 401s in auth api - Darwin](https://app.asana.com/0/0/1208959507432558) we found that the refreshAuthTokenIfNeeded is being called without a proper check if user is authenticated (and tokens are present). It also includes BSK check -> duckduckgo/BrowserServicesKit@fb809ed **Steps to test this PR**: 1. Ensure no PP is on the device 2. Open PP purchase page 3. Check if `refreshAuthTokenIfNeeded` was not called and no calls to `validate_token` endpoint were made. 4. Purchase or activate subscription 5. Open add/edit email page 6. Check if `refreshAuthTokenIfNeeded` was properly called with a call to `validate_token` endpoint. **Definition of Done (Internal Only)**: * [ ] Does this PR satisfy our [Definition of Done](https://app.asana.com/0/1202500774821704/1207634633537039/f)? **Copy Testing**: * [ ] Use of correct apostrophes in new copy, ie `’` rather than `'` **Orientation Testing**: * [ ] Portrait * [ ] Landscape **Device Testing**: * [ ] iPhone SE (1st Gen) * [ ] iPhone 8 * [ ] iPhone X * [ ] iPhone 14 Pro * [ ] iPad **OS Testing**: * [ ] iOS 15 * [ ] iOS 16 * [ ] iOS 17 **Theme Testing**: * [ ] Light theme * [ ] Dark theme --- ###### Internal references: [Software Engineering Expectations](https://app.asana.com/0/59792373528535/199064865822552) [Technical Design Template](https://app.asana.com/0/59792373528535/184709971311943)
1 parent d70d5cd commit 02a9657

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

DuckDuckGo.xcodeproj/project.pbxproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -11723,7 +11723,7 @@
1172311723
repositoryURL = "https://github.com/DuckDuckGo/BrowserServicesKit";
1172411724
requirement = {
1172511725
kind = exactVersion;
11726-
version = 221.0.0;
11726+
version = "221.0.0-1";
1172711727
};
1172811728
};
1172911729
9F8FE9472BAE50E50071E372 /* XCRemoteSwiftPackageReference "lottie-spm" */ = {

DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
"kind" : "remoteSourceControl",
3333
"location" : "https://github.com/DuckDuckGo/BrowserServicesKit",
3434
"state" : {
35-
"revision" : "9975e63265e617ce9c25ae1be6d531f6de5e6592",
36-
"version" : "221.0.0"
35+
"revision" : "276754fc1efab85c39a77da64e68439e7f105de3",
36+
"version" : "221.0.0-1"
3737
}
3838
},
3939
{
@@ -138,7 +138,7 @@
138138
{
139139
"identity" : "swift-argument-parser",
140140
"kind" : "remoteSourceControl",
141-
"location" : "https://github.com/apple/swift-argument-parser",
141+
"location" : "https://github.com/apple/swift-argument-parser.git",
142142
"state" : {
143143
"revision" : "0fbc8848e389af3bb55c182bc19ca9d5dc2f255b",
144144
"version" : "1.4.0"

DuckDuckGo/Subscription/UserScripts/SubscriptionPagesUseSubscriptionFeature.swift

+7-3
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,14 @@ final class SubscriptionPagesUseSubscriptionFeature: Subfeature, ObservableObjec
194194
// MARK: Broker Methods (Called from WebView via UserScripts)
195195

196196
func getSubscription(params: Any, original: WKScriptMessage) async -> Encodable? {
197-
await appStoreAccountManagementFlow.refreshAuthTokenIfNeeded()
198-
let authToken = accountManager.authToken ?? Constants.empty
197+
guard accountManager.isUserAuthenticated else { return [Constants.token: Constants.empty] }
199198

200-
return [Constants.token: authToken]
199+
switch await appStoreAccountManagementFlow.refreshAuthTokenIfNeeded() {
200+
case .success(let currentAuthToken):
201+
return [Constants.token: currentAuthToken]
202+
case .failure:
203+
return [Constants.token: Constants.empty]
204+
}
201205
}
202206

203207
func getSubscriptionOptions(params: Any, original: WKScriptMessage) async -> Encodable? {

0 commit comments

Comments
 (0)