Skip to content

Commit

Permalink
fix: remove redundant remove tokens (#67)
Browse files Browse the repository at this point in the history
* fix: remove redundant removeToken calls

* chore: bump version
  • Loading branch information
porcellus authored Jul 24, 2024
1 parent a77b1c4 commit 98dfb71
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 21 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.4.1] - 2024-07-12

### Changes

- Removed redundant calls to `removeToken`

## [0.4.0] - 2024-06-05

### Changes
Expand Down
2 changes: 1 addition & 1 deletion SuperTokensIOS.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'SuperTokensIOS'
s.version = "0.4.0"
s.version = "0.4.1"
s.summary = 'SuperTokens SDK for using login and session management functionality in iOS apps'

# This description is used to generate tags and improve search results.
Expand Down
1 change: 1 addition & 0 deletions SuperTokensIOS/Classes/FrontToken.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ internal class FrontToken {
}

static func removeToken() {
AntiCSRF.removeToken()
let executionSemaphore = DispatchSemaphore(value: 0)

readWriteDispatchQueue.async(flags: .barrier) {
Expand Down
21 changes: 2 additions & 19 deletions SuperTokensIOS/Classes/SuperTokensURLProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,23 +144,18 @@ public class SuperTokensURLProtocol: URLProtocol {
if unauthResponse.status == .RETRY {
self.requestForRetry = mutableRequest
self.makeRequest()
} else {
SuperTokensURLProtocol.clearTokensIfRequired()

} else {
if unauthResponse.error != nil {
self.resolveToUser(data: nil, response: nil, error: unauthResponse.error)
} else {
self.resolveToUser(data: data, response: response, error: unauthResponse.error)
}
}
})
} else {
SuperTokensURLProtocol.clearTokensIfRequired()

} else {
self.resolveToUser(data: data, response: response, error: error)
}
} else {
SuperTokensURLProtocol.clearTokensIfRequired()
self.resolveToUser(data: data, response: response, error: error)
}
}).resume()
Expand Down Expand Up @@ -249,8 +244,6 @@ public class SuperTokensURLProtocol: URLProtocol {
frontTokenheaderFromResponse: frontTokenInHeaders == nil ? "remove" : frontTokenInHeaders!
)

SuperTokensURLProtocol.clearTokensIfRequired()

if httpResponse.statusCode >= 300 {
semaphore.signal()
callback(UnauthorisedResponse(status: UnauthorisedResponse.UnauthorisedStatus.API_ERROR, error: SuperTokensError.apiError(message: "Refresh API returned with status code: \(httpResponse.statusCode)")))
Expand All @@ -276,7 +269,6 @@ public class SuperTokensURLProtocol: URLProtocol {
SuperTokens.config!.eventHandler(.REFRESH_SESSION)
callback(UnauthorisedResponse(status: UnauthorisedResponse.UnauthorisedStatus.RETRY))
} else {
SuperTokensURLProtocol.clearTokensIfRequired()
semaphore.signal()
callback(UnauthorisedResponse(status: UnauthorisedResponse.UnauthorisedStatus.API_ERROR, error: error))
}
Expand All @@ -289,13 +281,4 @@ public class SuperTokensURLProtocol: URLProtocol {
public override func stopLoading() {
// Do nothing, this is required to be implemented
}

static func clearTokensIfRequired() {
let preRequestLocalSessionState = Utils.getLocalSessionState()

if preRequestLocalSessionState.status == .NOT_EXISTS {
AntiCSRF.removeToken()
FrontToken.removeToken()
}
}
}
2 changes: 1 addition & 1 deletion SuperTokensIOS/Classes/Version.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ import Foundation

internal class Version {
static let supported_fdi: [String] = ["1.16", "1.17", "1.18", "1.19", "2.0", "3.0"]
static let sdkVersion = "0.4.0"
static let sdkVersion = "0.4.1"
}

0 comments on commit 98dfb71

Please sign in to comment.