Sign-up
Amplify provides a client library that enables you to interact with backend resources such as Amplify Auth.
To get started, you can use the signUp()
API to create a new user in your backend:
ArrayList<AuthUserAttribute> attributes = new ArrayList<>();attributes.add(new AuthUserAttribute(AuthUserAttributeKey.email(), "my@email.com"));attributes.add(new AuthUserAttribute(AuthUserAttributeKey.phoneNumber(), "+15551234567"));
Amplify.Auth.signUp( "username", "Password123", AuthSignUpOptions.builder().userAttributes(attributes).build(), result -> Log.i("AuthQuickstart", result.toString()), error -> Log.e("AuthQuickstart", error.toString()));
val attrs = mapOf( AuthUserAttributeKey.email() to "my@email.com", AuthUserAttributeKey.phoneNumber() to "+15551234567")val options = AuthSignUpOptions.builder() .userAttributes(attrs.map { AuthUserAttribute(it.key, it.value) }) .build()Amplify.Auth.signUp("username", "Password123", options, { Log.i("AuthQuickstart", "Sign up result = $it") }, { Log.e("AuthQuickstart", "Sign up failed", it) })
val attrs = mapOf( AuthUserAttributeKey.email() to "my@email.com", AuthUserAttributeKey.phoneNumber() to "+15551234567")val options = AuthSignUpOptions.builder() .userAttributes(attrs.map { AuthUserAttribute(it.key, it.value) }) .build()try { val result = Amplify.Auth.signUp("username", "Password123", options) Log.i("AuthQuickstart", "Sign up OK: $result")} catch (error: AuthException) { Log.e("AuthQuickstart", "Sign up failed", error)}
ArrayList<AuthUserAttribute> attributes = new ArrayList<>();attributes.add(new AuthUserAttribute(AuthUserAttributeKey.email(), "my@email.com"));attributes.add(new AuthUserAttribute(AuthUserAttributeKey.phoneNumber(), "+15551234567"));
RxAmplify.Auth.signUp( "username", "Password123", AuthSignUpOptions.builder().userAttributes(attributes).build()) .subscribe( result -> Log.i("AuthQuickstart", result.toString()), error -> Log.e("AuthQuickstart", error.toString()) );
The signUp
API response will include a nextStep
property, which can be used to determine if further action is required. It may return the following next steps:
Next Step | Description |
---|---|
CONFIRM_SIGN_UP_STEP | The sign up needs to be confirmed by collecting a code from the user and calling confirmSignUp . |
DONE | The sign up process has been fully completed. |
Confirm sign-up
By default, each user that signs up remains in the unconfirmed status until they verify with a confirmation code that was sent to their email or phone number. The following are the default verification methods used when either phone
or email
are used as loginWith
options.
Login option | User account verification channel |
---|---|
phone | Phone Number |
email | |
email and phone |
You can confirm the sign-up after receiving a confirmation code from the user:
Amplify.Auth.confirmSignUp( "username", "the code you received via email", result -> Log.i("AuthQuickstart", result.isSignUpComplete() ? "Confirm signUp succeeded" : "Confirm sign up not complete"), error -> Log.e("AuthQuickstart", error.toString()));
Amplify.Auth.confirmSignUp( "username", "the code you received via email", { result -> if (result.isSignUpComplete) { Log.i("AuthQuickstart", "Confirm signUp succeeded") } else { Log.i("AuthQuickstart","Confirm sign up not complete") } }, { Log.e("AuthQuickstart", "Failed to confirm sign up", it) })
try { val code = "code you received via email" val result = Amplify.Auth.confirmSignUp("username", code) if (result.isSignUpComplete) { Log.i("AuthQuickstart", "Signup confirmed") } else { Log.i("AuthQuickstart", "Signup confirmation not yet complete") }} catch (error: AuthException) { Log.e("AuthQuickstart", "Failed to confirm signup", error)}
RxAmplify.Auth.confirmSignUp("username", "the code you received via email") .subscribe( result -> Log.i("AuthQuickstart", result.isSignUpComplete() ? "Confirm signUp succeeded" : "Confirm sign up not complete"), error -> Log.e("AuthQuickstart", error.toString()) );
Sign up with passwordless methods
Your application's users can also sign up using passwordless methods. To learn more, visit the concepts page for passwordless.
SMS OTP
// Sign up using a phone numberArrayList<AuthUserAttribute> attributes = new ArrayList<>();attributes.add(new AuthUserAttribute(AuthUserAttributeKey.phoneNumber(), "+15551234567"));
Amplify.Auth.signUp( "hello@example.com", null, AuthSignUpOptions.builder().userAttributes(attributes).build(), result -> { if (result.isSignUpComplete()) { Log.i("AuthQuickstart", "Sign up is complete"); } else if (result.getNextStep().getSignUpStep() == AuthSignUpStep.CONFIRM_SIGN_UP_STEP) { Log.i("AuthQuickstart", "Code Deliver Medium: " + result.getNextStep().getCodeDeliveryDetails().getDeliveryMedium()); Log.i("AuthQuickstart", "Code Deliver Destination: " + result.getNextStep().getCodeDeliveryDetails().getDestination()); } }, error -> Log.e("AuthQuickstart", error.toString()));
// Confirm sign up with the OTP receivedAmplify.Auth.confirmSignUp( "hello@example.com", "123456", result -> { if (result.isSignUpComplete()) { Log.i("AuthQuickstart", "Sign up is complete"); } }, error -> Log.e("AuthQuickstart", error.toString()));
// Sign up using a phone numberval attributes = listOf( AuthUserAttribute(AuthUserAttributeKey.phoneNumber(), "+15555551234"))val options = AuthSignUpOptions .builder() .userAttributes(attributes) .build()
Amplify.Auth.signUp( "hello@example.com", null, options, { result -> if (result.isSignUpComplete) { Log.i("AuthQuickstart", "Sign up is complete") } else if (result.nextStep.signUpStep == AuthSignUpStep.CONFIRM_SIGN_UP_STEP) { Log.i("AuthQuickstart", "Code Deliver Medium: " + "${result.nextStep.codeDeliveryDetails?.deliveryMedium}") Log.i("AuthQuickstart", "Code Deliver Destination: " + "${result.nextStep.codeDeliveryDetails?.destination}") } }, { Log.e("AuthQuickstart", "Failed to sign up", it) })
// Confirm sign up with the OTP receivedAmplify.Auth.confirmSignUp( "hello@example.com", "123456", { result -> if (result.nextStep.signUpStep == AuthSignUpStep.DONE) { Log.i("AuthQuickstart", "Sign up is complete") } }, { Log.e("AuthQuickstart", "Failed to sign up", it) })
// Sign up using a phone numberval attributes = listOf( AuthUserAttribute(AuthUserAttributeKey.phoneNumber(), "+15555551234"))val options = AuthSignUpOptions .builder() .userAttributes(attributes) .build()var result = Amplify.Auth.signUp("hello@example.com", null, options)
if (result.isSignUpComplete) { Log.i("AuthQuickstart", "Sign up is complete")} else if (result.nextStep.signUpStep == AuthSignUpStep.CONFIRM_SIGN_UP_STEP) { Log.i("AuthQuickstart", "Code Deliver Medium: " + "${result.nextStep.codeDeliveryDetails?.deliveryMedium}") Log.i("AuthQuickstart", "Code Deliver Destination: " + "${result.nextStep.codeDeliveryDetails?.destination}")}
// Confirm sign up with the OTP receivedresult = Amplify.Auth.confirmSignUp( "hello@example.com", "123456")
if (result.nextStep.signUpStep == AuthSignUpStep.DONE) { Log.i("AuthQuickstart", "Sign up is complete")}
// Sign up using a phone numberArrayList<AuthUserAttribute> attributes = new ArrayList<>();attributes.add(new AuthUserAttribute(AuthUserAttributeKey.phoneNumber(), "+15551234567"));
RxAmplify.Auth.signUp( "hello@example.com", null, AuthSignUpOptions.builder().userAttributes(attributes).build()) .subscribe( result -> { if (result.isSignUpComplete()) { Log.i("AuthQuickstart", "Sign up is complete"); } else if (result.getNextStep().getSignUpStep() == AuthSignUpStep.CONFIRM_SIGN_UP_STEP) { Log.i("AuthQuickstart", "Code Deliver Medium: " + result.getNextStep().getCodeDeliveryDetails().getDeliveryMedium()); Log.i("AuthQuickstart", "Code Deliver Destination: " + result.getNextStep().getCodeDeliveryDetails().getDestination()); } }, error -> Log.e("AuthQuickstart", error.toString()) );
// Confirm sign up with the OTP receivedRxAmplify.Auth.confirmSignUp( "hello@example.com", "123456") .subscribe( result -> { if (result.isSignUpComplete()) { Log.i("AuthQuickstart", "Sign up is complete"); } }, error -> Log.e("AuthQuickstart", error.toString()) );
Email OTP
// Sign up using an email addressArrayList<AuthUserAttribute> attributes = new ArrayList<>();attributes.add(new AuthUserAttribute(AuthUserAttributeKey.email(), "hello@example.com"));
Amplify.Auth.signUp( "hello@example.com", null, AuthSignUpOptions.builder().userAttributes(attributes).build(), result -> { if (result.isSignUpComplete()) { Log.i("AuthQuickstart", "Sign up is complete"); } else if (result.getNextStep().getSignUpStep() == AuthSignUpStep.CONFIRM_SIGN_UP_STEP) { Log.i("AuthQuickstart", "Code Deliver Medium: " + result.getNextStep().getCodeDeliveryDetails().getDeliveryMedium()); Log.i("AuthQuickstart", "Code Deliver Destination: " + result.getNextStep().getCodeDeliveryDetails().getDestination()); } }, error -> Log.e("AuthQuickstart", error.toString()));
// Confirm sign up with the OTP receivedAmplify.Auth.confirmSignUp( "hello@example.com", "123456", result -> { if (result.isSignUpComplete()) { Log.i("AuthQuickstart", "Sign up is complete"); } }, error -> Log.e("AuthQuickstart", error.toString()));
// Sign up using an email addressval attributes = listOf( AuthUserAttribute(AuthUserAttributeKey.email(), "my@email.com"))val options = AuthSignUpOptions .builder() .userAttributes(attributes) .build()
Amplify.Auth.signUp( "hello@example.com", null, options, { result -> if (result.isSignUpComplete) { Log.i("AuthQuickstart", "Sign up is complete") } else if (result.nextStep.signUpStep == AuthSignUpStep.CONFIRM_SIGN_UP_STEP) { Log.i("AuthQuickstart", "Code Deliver Medium: " + "${result.nextStep.codeDeliveryDetails?.deliveryMedium}") Log.i("AuthQuickstart", "Code Deliver Destination: " + "${result.nextStep.codeDeliveryDetails?.destination}") } }, { Log.e("AuthQuickstart", "Failed to sign up", it) })
// Confirm sign up with the OTP receivedAmplify.Auth.confirmSignUp( "hello@example.com", "123456", { result -> if (result.nextStep.signUpStep == AuthSignUpStep.DONE) { Log.i("AuthQuickstart", "Sign up is complete") } }, { Log.e("AuthQuickstart", "Failed to sign up", it) })
// Sign up using an email addressval attributes = listOf( AuthUserAttribute(AuthUserAttributeKey.email(), "my@email.com"))val options = AuthSignUpOptions .builder() .userAttributes(attributes) .build()var result = Amplify.Auth.signUp("hello@example.com", null, options)
if (result.isSignUpComplete) { Log.i("AuthQuickstart", "Sign up is complete")} else if (result.nextStep.signUpStep == AuthSignUpStep.CONFIRM_SIGN_UP_STEP) { Log.i("AuthQuickstart", "Code Deliver Medium: " + "${result.nextStep.codeDeliveryDetails?.deliveryMedium}") Log.i("AuthQuickstart", "Code Deliver Destination: " + "${result.nextStep.codeDeliveryDetails?.destination}")}
// Confirm sign up with the OTP receivedresult = Amplify.Auth.confirmSignUp( "hello@example.com", "123456")
if (result.nextStep.signUpStep == AuthSignUpStep.DONE) { Log.i("AuthQuickstart", "Sign up is complete")}
// Sign up using an email addressArrayList<AuthUserAttribute> attributes = new ArrayList<>();attributes.add(new AuthUserAttribute(AuthUserAttributeKey.email(), "my@email.com"));
RxAmplify.Auth.signUp( "hello@example.com", null, AuthSignUpOptions.builder().userAttributes(attributes).build()) .subscribe( result -> { if (result.isSignUpComplete()) { Log.i("AuthQuickstart", "Sign up is complete"); } else if (result.getNextStep().getSignUpStep() == AuthSignUpStep.CONFIRM_SIGN_UP_STEP) { Log.i("AuthQuickstart", "Code Deliver Medium: " + result.getNextStep().getCodeDeliveryDetails().getDeliveryMedium()); Log.i("AuthQuickstart", "Code Deliver Destination: " + result.getNextStep().getCodeDeliveryDetails().getDestination()); } }, error -> Log.e("AuthQuickstart", error.toString()) );
// Confirm sign up with the OTP receivedRxAmplify.Auth.confirmSignUp( "hello@example.com", "123456") .subscribe( result -> { if (result.isSignUpComplete()) { Log.i("AuthQuickstart", "Sign up is complete"); } }, error -> Log.e("AuthQuickstart", error.toString()) );
Auto Sign In
private void confirmSignUp(String username, String confirmationCode) { // Confirm sign up with the OTP received then auto sign in Amplify.Auth.confirmSignUp( username, confirmationCode, result -> { if (result.getNextStep().getSignUpStep() == AuthSignUpStep.COMPLETE_AUTO_SIGN_IN) { Log.i("AuthQuickstart", "Sign up is complete, auto sign in"); autoSignIn(); } }, error -> Log.e("AuthQuickstart", error.toString()) );}
private void autoSignIn() { Amplify.Auth.autoSignIn( result -> Log.i("AuthQuickstart", "Sign in is complete"), error -> Log.e("AuthQuickstart", error.toString()) );}
fun confirmSignUp(username: String, confirmationCode: String) { // Confirm sign up with the OTP received Amplify.Auth.confirmSignUp( username, confirmationCode, { signUpResult -> if (signUpResult.nextStep.signUpStep == AuthSignUpStep.COMPLETE_AUTO_SIGN_IN) { Log.i("AuthQuickstart", "Sign up is complete, auto sign in") autoSignIn() } }, { Log.e("AuthQuickstart", "Failed to sign up", it) } )}fun autoSignIn() { Amplify.Auth.autoSignIn( { signInResult -> Log.i("AuthQuickstart", "Sign in is complete") }, { Log.e("AuthQuickstart", "Failed to sign in", it) } )}
suspend fun confirmSignUp(username: String, confirmationCode: String) { // Confirm sign up with the OTP received then auto sign in val result = Amplify.Auth.confirmSignUp( "hello@example.com", "123456" )
if (result.nextStep.signUpStep == AuthSignUpStep.COMPLETE_AUTO_SIGN_IN) { Log.i("AuthQuickstart", "Sign up is complete, auto sign in") autoSignIn() }}
suspend fun autoSignIn() { val result = Amplify.Auth.autoSignIn() if (result.isSignedIn) { Log.i("AuthQuickstart", "Sign in is complete") } else { Log.e("AuthQuickstart", "Sign in did not complete $result") }}
private void confirmSignUp(String username, String confirmationCode) { // Confirm sign up with the OTP received then auto sign in RxAmplify.Auth.confirmSignUp( username, confirmationCode ) .subscribe( result -> { if (result.getNextStep().getSignUpStep() == AuthSignUpStep.COMPLETE_AUTO_SIGN_IN) { Log.i("AuthQuickstart", "Sign up is complete, auto sign in"); autoSignIn(); } }, error -> Log.e("AuthQuickstart", error.toString()) );}
private void autoSignIn() { RxAmplify.Auth.autoSignIn() .subscribe( result -> Log.i("AuthQuickstart", "Sign in is complete" + result.toString()), error -> Log.e("AuthQuickstart", error.toString()) );}