Skip to content

Commit

Permalink
fix(auth): don't call removeSession prematurely (#416)
Browse files Browse the repository at this point in the history
  • Loading branch information
grdsdev committed Jun 7, 2024
1 parent 0c99154 commit 00221a8
Showing 1 changed file with 4 additions and 32 deletions.
36 changes: 4 additions & 32 deletions Sources/Auth/AuthClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,6 @@ public final class AuthClient: Sendable {
}

private func _signUp(request: HTTPRequest) async throws -> AuthResponse {
await sessionManager.remove()

let response = try await api.execute(request).decoded(
as: AuthResponse.self,
decoder: configuration.decoder
Expand Down Expand Up @@ -271,8 +269,6 @@ public final class AuthClient: Sendable {
}

private func _signIn(request: HTTPRequest) async throws -> Session {
await sessionManager.remove()

let session = try await api.execute(request).decoded(
as: Session.self,
decoder: configuration.decoder
Expand Down Expand Up @@ -302,8 +298,6 @@ public final class AuthClient: Sendable {
data: [String: AnyJSON]? = nil,
captchaToken: String? = nil
) async throws {
await sessionManager.remove()

let (codeChallenge, codeChallengeMethod) = prepareForPKCE()

_ = try await api.execute(
Expand Down Expand Up @@ -348,7 +342,6 @@ public final class AuthClient: Sendable {
data: [String: AnyJSON]? = nil,
captchaToken: String? = nil
) async throws {
await sessionManager.remove()
_ = try await api.execute(
.init(
url: configuration.url.appendingPathComponent("otp"),
Expand Down Expand Up @@ -378,8 +371,6 @@ public final class AuthClient: Sendable {
redirectTo: URL? = nil,
captchaToken: String? = nil
) async throws -> SSOResponse {
await sessionManager.remove()

let (codeChallenge, codeChallengeMethod) = prepareForPKCE()

return try await api.execute(
Expand Down Expand Up @@ -413,8 +404,6 @@ public final class AuthClient: Sendable {
redirectTo: URL? = nil,
captchaToken: String? = nil
) async throws -> SSOResponse {
await sessionManager.remove()

let (codeChallenge, codeChallengeMethod) = prepareForPKCE()

return try await api.execute(
Expand Down Expand Up @@ -834,8 +823,7 @@ public final class AuthClient: Sendable {
)
)
)
),
shouldRemoveSession: type != .emailChange
)
)
}

Expand All @@ -861,19 +849,11 @@ public final class AuthClient: Sendable {
)
)
)
),
shouldRemoveSession: type != .phoneChange
)
)
}

private func _verifyOTP(
request: HTTPRequest,
shouldRemoveSession: Bool
) async throws -> AuthResponse {
if shouldRemoveSession {
await sessionManager.remove()
}

private func _verifyOTP(request: HTTPRequest) async throws -> AuthResponse {
let response = try await api.execute(request).decoded(
as: AuthResponse.self,
decoder: configuration.decoder
Expand All @@ -897,10 +877,6 @@ public final class AuthClient: Sendable {
emailRedirectTo: URL? = nil,
captchaToken: String? = nil
) async throws {
if type != .emailChange {
await sessionManager.remove()
}

_ = try await api.execute(
HTTPRequest(
url: configuration.url.appendingPathComponent("resend"),
Expand Down Expand Up @@ -934,11 +910,7 @@ public final class AuthClient: Sendable {
type: ResendMobileType,
captchaToken: String? = nil
) async throws -> ResendMobileResponse {
if type != .phoneChange {
await sessionManager.remove()
}

return try await api.execute(
try await api.execute(
HTTPRequest(
url: configuration.url.appendingPathComponent("resend"),
method: .post,
Expand Down

0 comments on commit 00221a8

Please sign in to comment.