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()) );