Skip to content

Commit ff83090

Browse files
committed
Add Android CONTINUE_SIGN_IN_WITH_MFA_SELECTION example
1 parent 22c8c58 commit ff83090

File tree

1 file changed

+34
-0
lines changed
  • src/pages/[platform]/build-a-backend/auth/concepts/multi-factor-authentication

1 file changed

+34
-0
lines changed

src/pages/[platform]/build-a-backend/auth/concepts/multi-factor-authentication/index.mdx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,40 @@ async function handleMFASelection(mfaType: MfaType) {
130130
```
131131
</InlineFilter>
132132

133+
<InlineFilter filters={["android"]}>
134+
```kotlin
135+
fun signIn(username: String, password: String) {
136+
val result: AuthSignInResult
137+
try {
138+
result = Amplify.Auth.signIn(username, password)
139+
} catch (e: AuthException) {
140+
Log.e("MFASelection", "Failed to sign in", e)
141+
}
142+
handleNextSignInStep(username, result.nextStep)
143+
}
144+
145+
fun handleNextSignInStep(
146+
username: String,
147+
nextStep: AuthNextSignInStep
148+
) {
149+
when (nextStep.signInStep) {
150+
AuthSignInStep.CONTINUE_SIGN_IN_WITH_MFA_SELECTION -> {
151+
// User has multiple MFA methods and none are preferred
152+
promptUserForMfaType(nextStep.allowedMFATypes)
153+
}
154+
else -> {
155+
// Handle other SignInSteps
156+
}
157+
}
158+
}
159+
160+
fun promptUserForMfaType(mfaTypes: Set<MFAType>?) {
161+
// Prompt user to select one of the passed-in MFA Types
162+
// Then invoke Amplify.Auth.confirmSignIn(selectedMfaType.challengeResponse)
163+
}
164+
```
165+
</InlineFilter>
166+
133167
<InlineFilter filters={["swift", "flutter"]}>
134168
If multiple MFA methods are enabled for the user, and none are set as preferred, the `signIn` API will return `continueSignInWithMFASelection` as the next step in the auth flow. During this scenario, the user should be prompted to select the MFA method they want to use to sign in and their preference should be passed to `confirmSignIn`.
135169
</InlineFilter>

0 commit comments

Comments
 (0)