Amplify UI

Authenticator

Authenticator component adds complete authentication flows to your application with minimal boilerplate.

The Authenticator component adds complete authentication flows to your application with minimal boilerplate.

Quick start

Setup with Amplify Gen 2 backend

To get up and running with the Authenticator, follow the Amplify Gen2 quickstart guide.

Setup with Amplify Gen 1 backend

To setup Amplify using the Gen1 CLI, follow the steps below:

Step 1. Configure backend

The Authenticator works seamlessly with the Amplify CLI to automatically work with your backend.

First, update @aws-amplify/cli with npm or yarn if you're using a version before 6.4.0:

npm install -g @aws-amplify/cli@latest
yarn global add @aws-amplify/cli@latest

Run amplify add auth to configure how you want the Authenticator and its associated Cognito resources to behave. If you want more details on all of the options available in this step, please check out the Amplify for Swift Library Authentication getting started page.

amplify add auth
amplify push

Alternatively, if you have an existing backend, run amplify pull to sync your amplifyconfiguration.json file:

amplify pull

Step 2. Install dependencies

Open your project in Xcode and select File > Add Packages... and add the following dependencies:

  • Amplify Library for Swift: Enter its GitHub URL (https://github.com/aws-amplify/amplify-swift), select Up to Next Major Version and click Add Package

    • Select the following libraries:
      • Amplify
      • AWSCognitoAuthPlugin
  • Amplify UI Swift - Authenticator: Enter its GitHub URL (https://github.com/aws-amplify/amplify-ui-swift-authenticator), select Up to Next Major Version and click Add Package

    • Select the following library:
      • Authenticator

Step 3. Add the Authenticator

The quickest way to get started is by adding the Authenticator view as the entry point in your application.

Once an end-user has created an account and/or signed in, the provided content is displayed with access to the user.

import Amplify
import Authenticator
import AWSCognitoAuthPlugin
import SwiftUI

@main
struct MyApp: App {
    init() {
        do {
            try Amplify.add(plugin: AWSCognitoAuthPlugin())
            try Amplify.configure()
        } catch {
            print("Unable to configure Amplify \(error)")
        }
    }

    var body: some Scene {
        WindowGroup {
            Authenticator { state in
                VStack {
                    Text("Hello, \(state.user.username)")
                    Button("Sign out") {
                        Task {
                            await state.signOut()
                        }
                    }
                }
            }
        }
    }
}

Next steps

Amplify open source software, documentation and community are supported by Amazon Web Services.

© 2024 Amazon Web Services, Inc. and its affiliates. All rights reserved. View the site terms and privacy policy.

Flutter and the related logo are trademarks of Google LLC. We are not endorsed by or affiliated with Google LLC.