fix(swift-ios): serialize connect sign-out
This commit is contained in:
2 files changed
+14
-3
No files matched your search
@@ -204,7 +204,6 @@ public final class T3ConnectController {
|
||||
/// A successful authentication flow is the only action that may restore a
|
||||
/// locally signed-out Clerk session.
|
||||
public func refreshAfterAuthentication() async {
|
||||
guard !isSignOutInProgress else { return }
|
||||
isLocalAuthorizationInvalidated = false
|
||||
authorizationGeneration &+= 1
|
||||
await refresh()
|
||||
@@ -231,9 +230,13 @@ public final class T3ConnectController {
|
||||
await relay.clearTokenCache()
|
||||
await waitForAuthorizationOperations()
|
||||
|
||||
guard authorizationGeneration == signOutAuthorizationGeneration,
|
||||
isLocalAuthorizationInvalidated else { return }
|
||||
if let auth,
|
||||
let deviceID,
|
||||
let token = try? await auth.relayToken() {
|
||||
guard authorizationGeneration == signOutAuthorizationGeneration,
|
||||
isLocalAuthorizationInvalidated else { return }
|
||||
// Remote delivery must not outlive the signed-in session on this
|
||||
// install. A failed best-effort unregister must not trap the user
|
||||
// in an account they are trying to leave.
|
||||
|
||||
@@ -8,6 +8,7 @@ public struct T3ConnectView: View {
|
||||
@State private var isAuthPresented = false
|
||||
@State private var didFinishInitialRefresh = false
|
||||
@State private var connectingEnvironmentID: String?
|
||||
@State private var isSigningOut = false
|
||||
private let connectEnvironment:
|
||||
@MainActor (T3ConnectManagedEnvironmentCredential) async throws -> Void
|
||||
private let signOut: @MainActor () async -> Void
|
||||
@@ -31,9 +32,15 @@ public struct T3ConnectView: View {
|
||||
if controller.account != nil {
|
||||
ToolbarItem(placement: .topBarTrailing) {
|
||||
Button("Sign out", role: .destructive) {
|
||||
Task { await signOut() }
|
||||
guard !isSigningOut else { return }
|
||||
isSigningOut = true
|
||||
Task {
|
||||
await signOut()
|
||||
isSigningOut = false
|
||||
presentAuthenticationIfNeeded()
|
||||
}
|
||||
}
|
||||
.disabled(controller.isRefreshing)
|
||||
.disabled(controller.isRefreshing || isSigningOut)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -47,6 +54,7 @@ public struct T3ConnectView: View {
|
||||
}
|
||||
.onChange(of: controller.account?.id) { _, accountID in
|
||||
guard didFinishInitialRefresh,
|
||||
!isSigningOut,
|
||||
accountID == nil,
|
||||
controller.unavailableReason == nil else { return }
|
||||
isAuthPresented = true
|
||||
|
||||
Reference in new issue
Block a user