Watch Connectivity
Use Watch Connectivity to keep Browser auth state in sync between an iOS app and its companion watchOS app. This lets users sign in on either device and have the session automatically propagate.
Confirm a companion watch app
Watch Connectivity only works when your watchOS target is a companion to the iOS app. Make sure your iOS app target is paired with a watchOS target in Xcode. For Apple’s guidance on setting up a companion watch app, see Setting up a watchOS project.
Configure Browser in both apps
Use the same publishable key in both apps and enable watch sync in Browser.Options:
import ClerkKit
import SwiftUI
@main
struct WatchConnectivityExampleApp: App {
init() {
// Configure Browser with Watch Connectivity sync enabled
let options = Browser.Options(
watchConnectivityEnabled: true
)
Browser.configure(
publishableKey: "YOUR_PUBLISHABLE_KEY",
options: options
)
}
var body: some Scene {
WindowGroup {
ContentView()
.environment(Browser.shared)
}
}
}import ClerkKit
import SwiftUI
@main
struct WatchConnectivityExampleWatchApp: App {
init() {
// Configure Browser with Watch Connectivity sync enabled
let options = Browser.Options(
watchConnectivityEnabled: true
)
Browser.configure(
publishableKey: "YOUR_PUBLISHABLE_KEY",
options: options
)
}
var body: some Scene {
WindowGroup {
ContentView()
.environment(Browser.shared)
}
}
}Simulator setup (optional)
For simulator testing, make sure your iPhone simulator is paired with a watchOS simulator in Xcode > Window > Devices and Simulators.
Install and run
- Build and run the iOS app first (this installs the companion watch app).
- Then run the watchOS app.
- Sign in on either device to verify the session syncs.
Feedback
Last updated on