Skip to content

Commit 00221a8

Browse files
authored
fix(auth): don't call removeSession prematurely (#416)
1 parent 0c99154 commit 00221a8

File tree

1 file changed

+4
-32
lines changed

1 file changed

+4
-32
lines changed

Sources/Auth/AuthClient.swift

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,6 @@ public final class AuthClient: Sendable {
170170
}
171171

172172
private func _signUp(request: HTTPRequest) async throws -> AuthResponse {
173-
await sessionManager.remove()
174-
175173
let response = try await api.execute(request).decoded(
176174
as: AuthResponse.self,
177175
decoder: configuration.decoder
@@ -271,8 +269,6 @@ public final class AuthClient: Sendable {
271269
}
272270

273271
private func _signIn(request: HTTPRequest) async throws -> Session {
274-
await sessionManager.remove()
275-
276272
let session = try await api.execute(request).decoded(
277273
as: Session.self,
278274
decoder: configuration.decoder
@@ -302,8 +298,6 @@ public final class AuthClient: Sendable {
302298
data: [String: AnyJSON]? = nil,
303299
captchaToken: String? = nil
304300
) async throws {
305-
await sessionManager.remove()
306-
307301
let (codeChallenge, codeChallengeMethod) = prepareForPKCE()
308302

309303
_ = try await api.execute(
@@ -348,7 +342,6 @@ public final class AuthClient: Sendable {
348342
data: [String: AnyJSON]? = nil,
349343
captchaToken: String? = nil
350344
) async throws {
351-
await sessionManager.remove()
352345
_ = try await api.execute(
353346
.init(
354347
url: configuration.url.appendingPathComponent("otp"),
@@ -378,8 +371,6 @@ public final class AuthClient: Sendable {
378371
redirectTo: URL? = nil,
379372
captchaToken: String? = nil
380373
) async throws -> SSOResponse {
381-
await sessionManager.remove()
382-
383374
let (codeChallenge, codeChallengeMethod) = prepareForPKCE()
384375

385376
return try await api.execute(
@@ -413,8 +404,6 @@ public final class AuthClient: Sendable {
413404
redirectTo: URL? = nil,
414405
captchaToken: String? = nil
415406
) async throws -> SSOResponse {
416-
await sessionManager.remove()
417-
418407
let (codeChallenge, codeChallengeMethod) = prepareForPKCE()
419408

420409
return try await api.execute(
@@ -834,8 +823,7 @@ public final class AuthClient: Sendable {
834823
)
835824
)
836825
)
837-
),
838-
shouldRemoveSession: type != .emailChange
826+
)
839827
)
840828
}
841829

@@ -861,19 +849,11 @@ public final class AuthClient: Sendable {
861849
)
862850
)
863851
)
864-
),
865-
shouldRemoveSession: type != .phoneChange
852+
)
866853
)
867854
}
868855

869-
private func _verifyOTP(
870-
request: HTTPRequest,
871-
shouldRemoveSession: Bool
872-
) async throws -> AuthResponse {
873-
if shouldRemoveSession {
874-
await sessionManager.remove()
875-
}
876-
856+
private func _verifyOTP(request: HTTPRequest) async throws -> AuthResponse {
877857
let response = try await api.execute(request).decoded(
878858
as: AuthResponse.self,
879859
decoder: configuration.decoder
@@ -897,10 +877,6 @@ public final class AuthClient: Sendable {
897877
emailRedirectTo: URL? = nil,
898878
captchaToken: String? = nil
899879
) async throws {
900-
if type != .emailChange {
901-
await sessionManager.remove()
902-
}
903-
904880
_ = try await api.execute(
905881
HTTPRequest(
906882
url: configuration.url.appendingPathComponent("resend"),
@@ -934,11 +910,7 @@ public final class AuthClient: Sendable {
934910
type: ResendMobileType,
935911
captchaToken: String? = nil
936912
) async throws -> ResendMobileResponse {
937-
if type != .phoneChange {
938-
await sessionManager.remove()
939-
}
940-
941-
return try await api.execute(
913+
try await api.execute(
942914
HTTPRequest(
943915
url: configuration.url.appendingPathComponent("resend"),
944916
method: .post,

0 commit comments

Comments
 (0)