Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(auth): don't call removeSession prematurely #416

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading