Skip to content

Latest commit

 

History

History
90 lines (69 loc) · 2.4 KB

README.md

File metadata and controls

90 lines (69 loc) · 2.4 KB

Authenticator

Amplify Authenticator provides a complete drop-in implementation of an authentication flow for your Material 3 Jetpack Compose application using Amplify Authentication.

Usage

Prerequisites

Configure an Authentication backend with AWS Cognito. See the Amplify Authentication Getting Started Guide for details, or use the following steps with the Amplify CLI.

First initialize your Amplify project from your project root directory:

amplify init

And enter the following when prompted:

? Enter a name for the project
    `MyAmplifyApp`
? Initialize the project with the above configuration?
    `No`
? Enter a name for the environment
    `dev`
? Choose your default editor:
    `Android Studio`
? Choose the type of app that you're building
    `android`
? Where is your Res directory:
    `app/src/main/res`
? Select the authentication method you want to use:
    `AWS profile`
? Please choose the profile you want to use
    `default`

Then add the auth category:

amplify add auth

And enter the following when prompted:

? Do you want to use the default authentication and security configuration?
    `Default configuration`
? How do you want users to be able to sign in?
    `Username`
? Do you want to configure advanced settings?
    `No, I am done.`

Finally, push your changes to deploy your Authentication backend:

amplify push

Add Authenticator to your app

Add a dependency on Amplify Authenticator to your application's dependencies block:

dependencies {
    implementation("com.amplifyframework.ui:authenticator:1.4.0")
}

Ensure that the Auth plugin is configured for Amplify in your Application class:

override fun onCreate() {
    super.onCreate()
    Amplify.addPlugin(AWSCognitoAuthPlugin())
    Amplify.configure(applicationContext)
}

Add the Authenticator composable to wrap the content you want to display after the user has signed in:

@Composable
fun MyApp() {
    Authenticator {
        Text("You have signed in!")
    }
}