Use AWS SDK
For advanced use cases where Amplify does not provide the functionality you're looking for, you can retrieve the escape hatch to access the underlying SDK.
The escape hatch provides access to the underlying CognitoIdentityProviderClient
and CognitoIdentityClient
instance. Then retrieve the escape hatch with this code:
Gradle Imports
implementation "aws.sdk.kotlin:cognitoidentityprovider:KOTLIN_SDK_VERSION"implementation "aws.sdk.kotlin:cognitoidentity:KOTLIN_SDK_VERSION"
// 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); }});
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)}