I tried to use the Amplify SwiftUI Authenticator
I am using existing resources and I have created a cognate user pool manually by logging into my on my AWS account and using the management console
First I created a new iOS project (Xcode 14.3.1 - iPhone 14 Pro simulator with iOS 16.4)
Then I followed the instructions here (step 1 and 2 only as I am using existing resources) to import the packages https://docs.amplify.aws/lib/project-setup/create-application/q/platform/ios/#2-install-amplify-libraries
Then I followed the instructions here https://docs.amplify.aws/lib/project-setup/use-existing-resources/q/platform/ios/#2-initialize-amplify-in-the-application
On step 3 I chose Authentication Category
https://docs.amplify.aws/lib/auth/existing-resources/q/platform/ios/
My amplifyconfiguration.json looks like this
{
"auth": {
"plugins": {
"awsCognitoAuthPlugin": {
"IdentityManager": {
"Default": {}
},
"CognitoUserPool": {
"Default": {
"PoolId": "eu-west-1_DQWg7BIk5",
"AppClientId": "qj4jg75u82v2cgf3dl15lhsli",
"Region": "eu-west-1"
}
},
"Auth": {
"Default": {
"authenticationFlowType": "USER_SRP_AUTH",
}
}
}
}
}
}
and my swiftUI code looks like this
//
// amplify1App.swift
// amplify1
//
// Created by sumuhan on 10/07/2023.
//
import Amplify
import Authenticator
import AWSCognitoAuthPlugin
import SwiftUI
@main
struct amplify1App: App {
var body: some Scene {
WindowGroup {
Authenticator { state in
VStack {
Text("Hello, \(state.user.username)")
Button("Sign out") {
Task {
await state.signOut()
}
}
}
}
}
}
init() {
do {
try Amplify.add(plugin: AWSCognitoAuthPlugin())
try Amplify.configure()
print("Amplify configured with auth plugin")
} catch {
print("Failed to initialize Amplify with \(error)")
}
}
}
however when I run the code I got a message in the simulator saying something went wrong “There is a configuration problem that is preventing the authenticator from being displayed”
And I get the following output in the console
mplify configured with auth plugin
2023-07-13 20:33:11.606015+0100 amplify1[81221:3730960] [AmplifyConfiguration] passwordProtectionSettings is missing
2023-07-13 20:33:11.608755+0100 amplify1[81221:3730960] [AuthenticatorState] The operation couldn’t be completed. (Authenticator.AmplifyConfigurationError error 1.)
2023-07-13 20:33:11.609652+0100 amplify1[81221:3730960] [AuthenticatorState] Authenticator.AmplifyConfigurationError(name: "incorrectConfiguration")
2023-07-13 20:33:11.609736+0100 amplify1[81221:3730960] [AuthenticatorState] Unable to create AuthenticatorState
2023-07-13 20:33:11.714176+0100 amplify1[81221:3732383] [AuthenticatorState] The operation couldn’t be completed. (Authenticator.AmplifyConfigurationError error 1.)
2023-07-13 20:33:11.714282+0100 amplify1[81221:3732383] [AuthenticatorState] Authenticator.AmplifyConfigurationError(name: "incorrectConfiguration")
2023-07-13 20:33:11.714361+0100 amplify1[81221:3732383] [AuthenticatorState] Cannot reload state, the Authenticator is in error state.