Võ Văn ThươngOriginal post
Rank 1: Thread
Hi Appwrite team,
I’m integrating the Appwrite Swift SDK into a macOS app and am hitting an environment/runtime issue when starting OAuth.
App architecture
• macOS app built on AppKit lifecycle (@main class AppDelegate: NSApplicationDelegate).
• Main UI windows are NSWindow instances that embed SwiftUI content via NSHostingView.
• The sign-in sheet is a SwiftUI view (AuthSheetView) shown inside that hosted window.
At runtime the call logs:
Accessing Environment<OpenURLAction>'s value outside of being installed on a View. This will always read the default value and will not update.
Questions
- Does createOAuth2Session internally rely on SwiftUI’s openURL environment, and does that fail when the view is hosted inside an NSHostingView under an AppKit lifecycle?
- What’s the recommended way to trigger createOAuth2Session in a hybrid AppKit + SwiftUI macOS app?
• Should we supply a custom OpenURLAction or call an alternative API that works without openURL?
• Is there a configuration flag or parameter to force the SDK to use NSWorkspace.shared.open / ASWebAuthenticationSession on macOS instead of SwiftUI’s environment?
Thanks for any guidance or workarounds. Happy to provide more code or logs if needed.
Summary
Problem: OAuth flow not starting in macOS app integrated with Appwrite Swift SDK due to environment/runtime issue when starting OAuth.
Solution: The issue might be related to the OAuth2Session relying on SwiftUI's openURL environment, which fails when the view is hosted inside NSHostingView under an AppKit lifecycle. For a hybrid AppKit + SwiftUI macOS app, consider providing a custom OpenURLAction or calling an alternative SDK API that works without openURL. Additionally, check for any configuration flags or parameters to force the SDK to use NSWorkspace.shared.open or ASWebAuthenticationSession on macOS instead of SwiftUI's environment.