aws-amplify / aws-amplify/docs
Amplify Libraries Swift - Authentication - Sign In with Web UI - Looking for SwiftUI/UIKit example
- Dominant language
- MDX
- Stars
- 506
- Forks
- 1.1k
- Avg merge
- 3h 14m
- Merged PRs (30d)
- 1
Description
**Describe the content issue**:
I feel like there's some missing content here. I wasn't working from a UIViewController and was building a SwiftUI app, I wasn't sure If i wanted to go down the route of creating a UIViewRepresentable, and then get the UIWindow? I had no idea how to get this working, and went searching else where. I feel we should improve this documentation to include the entire UIViewController example and the SwiftUI example. In the end, I went with this, but not sure if this should be the recommended approach
Globally define:
```swift
// Use `@MainActor` since the window will be accessed from the UI, via a button tap for example.
@MainActor
private var window: UIWindow {
guard
let scene = UIApplication.shared.connectedScenes.first,
let windowSceneDelegate = scene.delegate as? UIWindowSceneDelegate,
let window = windowSceneDelegate.window as? UIWindow
else { return UIWindow() }
return window
}
```
```swift
func signInWithWebUI() async {
do {
let signInResult = try await Amplify.Auth.signInWithWebUI(presentationAnchor: window)
if signInResult.isSignedIn {
print("Sign in succeeded")
}
} catch let error as AuthError {
print("Sign in failed \(error)")
} catch {
print("Unexpected error: \(error)")
}
}
```
Then provide a simple SwiftUI example
```swift
struct ContentView: View {
var body: some View {
VStack {
Button("Sign In with HostedUI") {
Task {
await signInWithWebUI()
}
}
}
}
}
```
**URL page where content issue is**:
https://docs.amplify.aws/lib/auth/signin_web_ui/q/platform/ios/#update-infoplist
Contributor guide
Assessment
This issue has not been assessed yet.