Skip to content

Commit

Permalink
Only return authToken when subscription is active
Browse files Browse the repository at this point in the history
  • Loading branch information
miasma13 committed Apr 25, 2024
1 parent ba68b9d commit afaed7c
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ final class SubscriptionPagesUseSubscriptionFeature: Subfeature, ObservableObjec

private func resetSubscriptionFlow() {
setTransactionError(nil)

}

private func setTransactionError(_ error: UseSubscriptionError?) {
Expand All @@ -168,8 +169,20 @@ final class SubscriptionPagesUseSubscriptionFeature: Subfeature, ObservableObjec

// MARK: Broker Methods (Called from WebView via UserScripts)
func getSubscription(params: Any, original: WKScriptMessage) async -> Encodable? {
let authToken = AccountManager().authToken ?? Constants.empty
return [Constants.token: authToken]
guard let accessToken = AccountManager().accessToken,
let authToken = AccountManager().authToken
else { return [Constants.token: Constants.empty] }

let token: String

if case .success(let subscription) = await SubscriptionService.getSubscription(accessToken: accessToken),
subscription.isActive {
token = authToken
} else {
token = Constants.empty
}

return [Constants.token: token]
}

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

0 comments on commit afaed7c

Please sign in to comment.