Use AWS SDK
For advanced use cases where Amplify does not provide the functionality, you can retrieve an escape hatch to access the underlying Amazon Cognito client.
You can access the underlying CognitoIdentityProviderClient
and CognitoIdentityClient
as shown below
implementation "aws.sdk.kotlin:cognitoidentityprovider:1.0.44"implementation "aws.sdk.kotlin:cognitoidentity:1.0.44"
suspend fun resendCodeUsingEscapeHatch() { // Get the instance of AWSCognitoAuthPlugin val cognitoAuthPlugin = Amplify.Auth.getPlugin("awsCognitoAuthPlugin") val cognitoAuthService = cognitoAuthPlugin.escapeHatch as AWSCognitoAuthService
// Get the instance of CognitoIdentityProviderClient val cognitoIdentityProviderClient = cognitoAuthService.cognitoIdentityProviderClient val request = ResendConfirmationCodeRequest { clientId = "xxxxxxxxxxxxxxxx" username = "user1" } val response = cognitoIdentityProviderClient?.resendConfirmationCode(request)}
// Get the instance of AWSCognitoAuthPluginAWSCognitoAuthPlugin cognitoAuthPlugin = (AWSCognitoAuthPlugin) Amplify.Auth.getPlugin("awsCognitoAuthPlugin");
// Get the instance of CognitoIdentityProviderClientCognitoIdentityProviderClient client = cognitoAuthPlugin.getEscapeHatch().getCognitoIdentityProviderClient();ResendConfirmationCodeRequest request = ResendConfirmationCodeRequest.Companion.invoke(dslBuilder -> { dslBuilder.setClientId("xxxxxxxxxxxxxxxx"); dslBuilder.setUsername("user1"); return null;});
assert client != null;client.resendConfirmationCode(request, new Continuation<ResendConfirmationCodeResponse>() { @NonNull @Override public CoroutineContext getContext() { return GlobalScope.INSTANCE.getCoroutineContext(); }
@Override public void resumeWith(@NonNull Object resultOrException) { Log.i(TAG, "Result: " + resultOrException); }});