Skip to content

Commit a456563

Browse files
committed
add additional detail to switching auth flows page
1 parent 943d681 commit a456563

File tree

1 file changed

+32
-15
lines changed
  • src/pages/[platform]/build-a-backend/auth/connect-your-frontend/switching-authentication-flows

1 file changed

+32
-15
lines changed

src/pages/[platform]/build-a-backend/auth/connect-your-frontend/switching-authentication-flows/index.mdx

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -171,18 +171,9 @@ await signIn({
171171
172172
## USER_AUTH flow
173173

174-
The `USER_AUTH` sign in flow will support the following methods of first factor authentication: `WEB_AUTHN`, `EMAIL_OTP`, `SMS_OTP`, `PASSWORD`, and `PASSWORD_SRP`.
174+
The `USER_AUTH` sign in flow supports the following methods as first factors for authentication: `WEB_AUTHN`, `EMAIL_OTP`, `SMS_OTP`, `PASSWORD`, and `PASSWORD_SRP`.
175175

176-
```ts
177-
type AuthFactorType =
178-
| "WEB_AUTHN"
179-
| "EMAIL_OTP"
180-
| "SMS_OTP"
181-
| "PASSWORD"
182-
| "PASSWORD_SRP";
183-
```
184-
185-
If the desired first factor is known before the sign in flow is initiated it can be passed to the initial sign in call.
176+
If the desired first factor is known when authentication is initiated it can be passed to the `signIn` API as the `preferredChallenge` to initiate the corresponding authentication flow.
186177

187178
```ts
188179
// PASSWORD_SRP / PASSWORD
@@ -199,19 +190,45 @@ const { nextStep } = await signIn({
199190

200191
// WEB_AUTHN / EMAIL_OTP / SMS_OTP
201192
// sign in with preferred passwordless challenge
202-
// no user input required at this step
193+
// no additional user input required at this step
203194
const { nextStep } = await signIn({
204-
username: "passwordless@mycompany.com",
195+
username: "hello@example.com",
205196
options: {
206197
authFlowType: "USER_AUTH",
207198
preferredChallenge: "WEB_AUTHN" // or "EMAIL_OTP" or "SMS_OTP"
208199
},
209200
});
210201
```
211202

212-
If the desired first factor is not known, the flow will continue to select an available first factor.
203+
If the desired first factor is not known or you would like to provide users with available options, it can be omitted from the initial `signIn` API call to discover which authentication first factors are available for a user via the `CONTINUE_SIGN_IN_WITH_FIRST_FACTOR_SELECTION` step.
204+
205+
```ts
206+
const { nextStep: signInNextStep } = await signIn({
207+
username: '+15551234567',
208+
options: {
209+
authFlowType: 'USER_AUTH',
210+
},
211+
});
212+
213+
if (
214+
signInNextStep.signInStep === 'CONTINUE_SIGN_IN_WITH_FIRST_FACTOR_SELECTION'
215+
) {
216+
// present user with list of available challenges
217+
console.log(`Available Challenges: ${signInNextStep.availableChallenges}`);
218+
219+
// respond with user selection using `confirmSignIn` API
220+
const { nextStep: nextConfirmSignInStep } = await confirmSignIn({
221+
challengeResponse: 'SMS_OTP', // or 'EMAIL_OTP', 'WEB_AUTHN', 'PASSWORD', 'PASSWORD_SRP'
222+
});
223+
}
224+
225+
```
226+
Also, note that if the `preferredChallenge` passed to the initial `signIn` API call is unavailable for the user, Amplify will also respond with the `CONTINUE_SIGN_IN_WITH_FIRST_FACTOR_SELECTION` next step.
227+
213228

214-
> For more information about determining a first factor, and signing in with passwordless authorization factors, please visit the [concepts page for passwordless](/[platform]/build-a-backend/auth/concepts/passwordless/)
229+
<Callout>
230+
For more information about determining a first factor, and signing in with passwordless authentication factors, please visit the [Passwordless](/[platform]/build-a-backend/auth/concepts/passwordless/) concepts page.
231+
</Callout>
215232

216233
## USER_PASSWORD_AUTH flow
217234

0 commit comments

Comments
 (0)