`Hi , I'm using this method to send OTP code in my email , but at first time , I received 3 different codes , In second time not problem on that , what the case ?
We have on here , View Model Class
Fragment Class
And JSON amplify Config.
private var awsTOTPInProgress = false
private val getAWSLoginOTP = SingleLiveData<Resource<AuthSignInResult>>()
val getAWSLoginOTPData: LiveData<Resource<AuthSignInResult>> get() = getAWSLoginOTP
viewModelScope.launch {
try {
getAWSLoginOTP.postValue(Resource.loading(null))
val amplify = Amplify.Auth
val options = AWSCognitoAuthSignInOptions.builder()
.authFlowType(AuthFlowType.CUSTOM_AUTH_WITHOUT_SRP)
.build()
amplify.signIn(username, "", options,
{ result ->
Log.d("AuthQuickstart", result.toJson().toString())
when {
result.isSignedIn -> {
Log.d("AuthQuickstart", "Sign in succeeded")
getAWSLoginOTP.postValue(Resource.success(result))
}
result.nextStep.signInStep.toString() == "CONFIRM_SIGN_IN_WITH_CUSTOM_CHALLENGE" -> {
getAWSLoginOTP.postValue(Resource.success(result))
}
else -> {
getAWSLoginOTP.postValue(Resource.error("You need to make a signup, please go to the signup page.", null))
}
}
awsTOTPInProgress = false
},
{ exception ->
Log.e("AuthQuickstart", "Failed to sign in", exception)
when {
exception.cause?.message.equals("Incorrect username or password.") -> {
getAWSLoginOTP.postValue(Resource.error("Incorrect Email Address!", null))
}
exception.message.equals("There is already a user signed in.") -> {
getAWSLoginOTP.postValue(Resource.error("There is already a user signed in.", null))
}
}
awsTOTPInProgress = false
}
)
} catch (exception: Exception) {
Log.e("AuthQuickstart", "Failed to sign in", exception)
getAWSLoginOTP.postValue(Resource.error("An error occurred during sign in.", null))
awsTOTPInProgress = false
}
}
#On Fragment I have this
viewModel.awsTOTP(username)
viewModel.getAWSLoginOTPData.observe(this, Observer {
when (it.status) {
Status.SUCCESS -> {
it.data.let { res ->
Log.e("AuthQuickStart", "Success")
}
}
I Want to know this from Android or From Backend
Amplify Version
implementation 'com.amplifyframework:aws-auth-cognito:2.7.1'
implementation 'com.amplifyframework:core:2.8.4'
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.3'
JSON AUTH
{
"UserAgent": "aws-amplify-cli/2.0",
"Version": "1.0",
"auth": {
"plugins": {
"awsCognitoAuthPlugin": {
"UserAgent": "aws-amplify-cli/0.1.0",
"Version": "0.1.0",
"IdentityManager": {
"Default": {}
},
"CredentialsProvider": {
"CognitoIdentity": {
"Default": {
"PoolId": "-",
"Region": "-"
}
}
},
"CognitoUserPool": {
"Default": {
"PoolId": "-",
"AppClientId": "-",`your text`
"AppClientSecret": "-",
"Region": "-"
}
},
"Auth": {
"Default": {
"authenticationFlowType": "CUSTOM_AUTH_WITHOUT_SRP"
}
}
}
}
}
}