Skip to content

Commit 3b62c84

Browse files
author
JoonWon Choi
committed
Introduce resumable signin feature with the docs
1 parent 2f191dc commit 3b62c84

File tree

1 file changed

+97
-62
lines changed
  • src/pages/[platform]/build-a-backend/auth/connect-your-frontend/sign-in

1 file changed

+97
-62
lines changed

src/pages/[platform]/build-a-backend/auth/connect-your-frontend/sign-in/index.mdx

Lines changed: 97 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ The quickest way to get started with Amplify Auth in your frontend application i
6969
<InlineFilter filters={["angular", "javascript", "nextjs", "react", "vue"]}>
7070

7171
```ts
72-
import { signIn } from 'aws-amplify/auth'
72+
import { signIn } from 'aws-amplify/auth';
7373

7474
await signIn({
75-
username: "[email protected]",
76-
password: "hunter2",
77-
})
75+
username: '[email protected]',
76+
password: 'hunter2'
77+
});
7878
```
7979

8080
</InlineFilter>
@@ -209,7 +209,7 @@ RxAmplify.Auth.signIn("username", "password")
209209
func signIn(username: String, password: String) async {
210210
do {
211211
let signInResult = try await Amplify.Auth.signIn(
212-
username: username,
212+
username: username,
213213
password: password
214214
)
215215
if signInResult.isSignedIn {
@@ -230,7 +230,7 @@ func signIn(username: String, password: String) async {
230230
func signIn(username: String, password: String) -> AnyCancellable {
231231
Amplify.Publisher.create {
232232
try await Amplify.Auth.signIn(
233-
username: username,
233+
username: username,
234234
password: password
235235
)
236236
}.sink {
@@ -253,28 +253,43 @@ func signIn(username: String, password: String) -> AnyCancellable {
253253

254254
The `signIn` API response will include a `nextStep` property, which can be used to determine if further action is required. It may return the following next steps:
255255

256-
<InlineFilter filters={["angular", "javascript", "react", "nextjs", "vue", "android"]}>
257-
- `CONFIRM_SIGN_IN_WITH_NEW_PASSWORD_REQUIRED` - The user was created with a temporary password and must set a new one. Complete the process with `confirmSignIn`.
258-
- `CONFIRM_SIGN_IN_WITH_CUSTOM_CHALLENGE` - The sign-in must be confirmed with a custom challenge response. Complete the process with `confirmSignIn`.
259-
- `CONFIRM_SIGN_IN_WITH_TOTP_CODE` - The sign-in must be confirmed with a TOTP code from the user. Complete the process with `confirmSignIn`.
260-
- `CONTINUE_SIGN_IN_WITH_TOTP_SETUP` - The TOTP setup process must be continued. Complete the process with `confirmSignIn`.
261-
- `CONFIRM_SIGN_IN_WITH_SMS_CODE` - The sign-in must be confirmed with a SMS code from the user. Complete the process with `confirmSignIn`.
262-
- `CONTINUE_SIGN_IN_WITH_MFA_SELECTION` - The user must select their mode of MFA verification before signing in. Complete the process with `confirmSignIn`.
263-
- `RESET_PASSWORD` - The user must reset their password via `resetPassword`.
264-
- `CONFIRM_SIGN_UP` - The user hasn't completed the sign-up flow fully and must be confirmed via `confirmSignUp`.
265-
- `DONE` - The sign in process has been completed.
256+
<InlineFilter
257+
filters={['angular', 'javascript', 'react', 'nextjs', 'vue', 'android']}
258+
>
259+
- `CONFIRM_SIGN_IN_WITH_NEW_PASSWORD_REQUIRED` - The user was created with a
260+
temporary password and must set a new one. Complete the process with
261+
`confirmSignIn`. - `CONFIRM_SIGN_IN_WITH_CUSTOM_CHALLENGE` - The sign-in must
262+
be confirmed with a custom challenge response. Complete the process with
263+
`confirmSignIn`. - `CONFIRM_SIGN_IN_WITH_TOTP_CODE` - The sign-in must be
264+
confirmed with a TOTP code from the user. Complete the process with
265+
`confirmSignIn`. - `CONTINUE_SIGN_IN_WITH_TOTP_SETUP` - The TOTP setup process
266+
must be continued. Complete the process with `confirmSignIn`. -
267+
`CONFIRM_SIGN_IN_WITH_SMS_CODE` - The sign-in must be confirmed with a SMS
268+
code from the user. Complete the process with `confirmSignIn`. -
269+
`CONTINUE_SIGN_IN_WITH_MFA_SELECTION` - The user must select their mode of MFA
270+
verification before signing in. Complete the process with `confirmSignIn`. -
271+
`RESET_PASSWORD` - The user must reset their password via `resetPassword`. -
272+
`CONFIRM_SIGN_UP` - The user hasn't completed the sign-up flow fully and must
273+
be confirmed via `confirmSignUp`. - `DONE` - The sign in process has been
274+
completed.
266275
</InlineFilter>
267276

268-
<InlineFilter filters={["swift", "flutter"]}>
269-
- `confirmSignInWithNewPassword` - The user was created with a temporary password and must set a new one. Complete the process with `confirmSignIn`.
270-
- `confirmSignInWithCustomChallenge` - The sign-in must be confirmed with a custom challenge response. Complete the process with `confirmSignIn`.
271-
- `confirmSignInWithTOTPCode` - The sign-in must be confirmed with a TOTP code from the user. Complete the process with `confirmSignIn`.
272-
- `continueSignInWithTOTPSetup` - The TOTP setup process must be continued. Complete the process with `confirmSignIn`.
273-
- `confirmSignInWithSMSMFACode` - The sign-in must be confirmed with a SMS code from the user. Complete the process with `confirmSignIn`.
274-
- `continueSignInWithMFASelection` - The user must select their mode of MFA verification before signing in. Complete the process with `confirmSignIn`.
275-
- `resetPassword` - The user must reset their password via `resetPassword`.
276-
- `confirmSignUp` - The user hasn't completed the sign-up flow fully and must be confirmed via `confirmSignUp`.
277-
- `done` - The sign in process has been completed.
277+
<InlineFilter filters={['swift', 'flutter']}>
278+
- `confirmSignInWithNewPassword` - The user was created with a temporary
279+
password and must set a new one. Complete the process with `confirmSignIn`. -
280+
`confirmSignInWithCustomChallenge` - The sign-in must be confirmed with a
281+
custom challenge response. Complete the process with `confirmSignIn`. -
282+
`confirmSignInWithTOTPCode` - The sign-in must be confirmed with a TOTP code
283+
from the user. Complete the process with `confirmSignIn`. -
284+
`continueSignInWithTOTPSetup` - The TOTP setup process must be continued.
285+
Complete the process with `confirmSignIn`. - `confirmSignInWithSMSMFACode` -
286+
The sign-in must be confirmed with a SMS code from the user. Complete the
287+
process with `confirmSignIn`. - `continueSignInWithMFASelection` - The user
288+
must select their mode of MFA verification before signing in. Complete the
289+
process with `confirmSignIn`. - `resetPassword` - The user must reset their
290+
password via `resetPassword`. - `confirmSignUp` - The user hasn't completed
291+
the sign-up flow fully and must be confirmed via `confirmSignUp`. - `done` -
292+
The sign in process has been completed.
278293
</InlineFilter>
279294

280295
For more information on handling the TOTP and MFA steps that may be returned, see [multi-factor authentication](/[platform]/build-a-backend/auth/concepts/multi-factor-authentication/).
@@ -284,20 +299,22 @@ For more information on handling the TOTP and MFA steps that may be returned, se
284299
<InlineFilter filters={["angular", "javascript", "nextjs", "react", "react-native", "vue"]}>
285300

286301
```ts title="src/main.ts"
287-
import { confirmSignIn, signIn } from 'aws-amplify/auth'
302+
import { confirmSignIn, signIn } from 'aws-amplify/auth';
288303

289304
const { nextStep } = await signIn({
290-
username: "[email protected]",
291-
password: "hunter2",
292-
})
305+
username: '[email protected]',
306+
password: 'hunter2'
307+
});
293308

294-
if (nextStep === "CONFIRM_SIGN_IN_WITH_SMS_CODE") {
309+
if (nextStep === 'CONFIRM_SIGN_IN_WITH_SMS_CODE') {
295310
await confirmSignIn({
296-
challengeResponse: "12345"
297-
})
311+
challengeResponse: '12345'
312+
});
298313
}
299314
```
300315

316+
`signIn` API even allows you to continue confirm sign-in process after a redirection to a different location requiring a full browser reload, such as redirecting from a Login Page to a Confirm MFA Code Page in a Multi-Page Application during the sign-in process.
317+
301318
</InlineFilter>
302319
<InlineFilter filters={["android"]}>
303320

@@ -351,39 +368,40 @@ func confirmSignIn() -> AnyCancellable {
351368
</InlineFilter>
352369

353370
{/* double-filter to conditionally display this section for only platforms that have examples */}
371+
354372
<InlineFilter filters={["javascript", "nextjs", "react"]}>
355373

356374
### Practical Example
357375

358376
<InlineFilter filters={["javascript", "nextjs", "react"]}>
359377

360378
```tsx title="src/App.tsx"
361-
import type { FormEvent } from "react"
362-
import { Amplify } from "aws-amplify"
379+
import type { FormEvent } from 'react';
380+
import { Amplify } from 'aws-amplify';
363381
// highlight-next-line
364-
import { signIn } from "aws-amplify/auth"
365-
import outputs from "../amplify_outputs.json"
382+
import { signIn } from 'aws-amplify/auth';
383+
import outputs from '../amplify_outputs.json';
366384

367-
Amplify.configure(outputs)
385+
Amplify.configure(outputs);
368386

369387
interface SignInFormElements extends HTMLFormControlsCollection {
370-
email: HTMLInputElement
371-
password: HTMLInputElement
388+
email: HTMLInputElement;
389+
password: HTMLInputElement;
372390
}
373391

374392
interface SignInForm extends HTMLFormElement {
375-
readonly elements: SignInFormElements
393+
readonly elements: SignInFormElements;
376394
}
377395

378396
export default function App() {
379397
async function handleSubmit(event: FormEvent<SignInForm>) {
380-
event.preventDefault()
381-
const form = event.currentTarget
398+
event.preventDefault();
399+
const form = event.currentTarget;
382400
// ... validate inputs
383401
await signIn({
384402
username: form.elements.email.value,
385-
password: form.elements.password.value,
386-
})
403+
password: form.elements.password.value
404+
});
387405
}
388406

389407
return (
@@ -394,14 +412,15 @@ export default function App() {
394412
<input type="password" id="password" name="password" />
395413
<input type="submit" />
396414
</form>
397-
)
415+
);
398416
}
399417
```
400418

401419
</InlineFilter>
402420
</InlineFilter>
403421

404422
{/* with multi-factor auth */}
423+
405424
## With multi-factor auth enabled
406425

407426
When multi-factor authentication (MFA) is **required** with SMS in your backend auth resource, you will need to pass the phone number during sign-up API call. If you are using the `email` or `username` as the primary sign-in mechanism, you will need to pass the `phone_number` attribute as a user attribute. This will change depending on if you enable SMS, TOTP, or both. Visit the [multi-factor authentication documentation](/[platform]/build-a-backend/auth/concepts/multi-factor-authentication/) to learn more about enabling MFA on your backend auth resource.
@@ -550,12 +569,28 @@ func signUp(username: String, password: String, email: String, phonenumber: Stri
550569

551570
</InlineFilter>
552571

553-
<InlineFilter filters={["angular", "javascript", "react", "nextjs", "vue", "flutter", "android"]}>
554-
You will then confirm sign-up, sign in, and receive a `nextStep` in the sign-in result of type `CONFIRM_SIGN_IN_WITH_SMS_MFA_CODE`. A confirmation code will also be texted to the phone number provided above. Pass the code you received to the `confirmSignIn` API:
572+
<InlineFilter
573+
filters={[
574+
'angular',
575+
'javascript',
576+
'react',
577+
'nextjs',
578+
'vue',
579+
'flutter',
580+
'android'
581+
]}
582+
>
583+
You will then confirm sign-up, sign in, and receive a `nextStep` in the
584+
sign-in result of type `CONFIRM_SIGN_IN_WITH_SMS_MFA_CODE`. A confirmation
585+
code will also be texted to the phone number provided above. Pass the code you
586+
received to the `confirmSignIn` API:
555587
</InlineFilter>
556588

557-
<InlineFilter filters={["swift"]}>
558-
You will then confirm sign-up, sign in, and receive a `nextStep` in the sign-in result of type `confirmSignInWithSMSMFACode`. A confirmation code will also be texted to the phone number provided above. Pass the code you received to the `confirmSignIn` API:
589+
<InlineFilter filters={['swift']}>
590+
You will then confirm sign-up, sign in, and receive a `nextStep` in the
591+
sign-in result of type `confirmSignInWithSMSMFACode`. A confirmation code will
592+
also be texted to the phone number provided above. Pass the code you received
593+
to the `confirmSignIn` API:
559594
</InlineFilter>
560595

561596
<InlineFilter filters={["android", "flutter", "react-native", "swift"]}>
@@ -595,7 +630,7 @@ Amplify.Auth.confirmSignIn("code received via SMS",
595630
```kotlin
596631
try {
597632
val result = Amplify.Auth.confirmSignIn("code received via SMS")
598-
Log.i("AuthQuickstart", "Confirmed signin: $result")
633+
Log.i("AuthQuickstart", "Confirmed signin: $result")
599634
} catch (error: AuthException) {
600635
Log.e("AuthQuickstart", "Failed to confirm signin", error)
601636
}
@@ -664,9 +699,9 @@ To sign in using an external identity provider such as Google, use the `signInWi
664699
<InlineFilter filters={["angular", "javascript", "nextjs", "react", "react-native", "vue"]}>
665700

666701
```ts
667-
import { signInWithRedirect } from "aws-amplify/auth"
702+
import { signInWithRedirect } from 'aws-amplify/auth';
668703

669-
signInWithRedirect({ provider: "Google" })
704+
signInWithRedirect({ provider: 'Google' });
670705
```
671706

672707
<Callout info>
@@ -677,13 +712,14 @@ signInWithRedirect({ provider: "Google" })
677712

678713
Alternatively if you have configured OIDC or SAML-based identity providers in your auth resource, you can specify a "custom" provider in `signInWithRedirect`:
679714

680-
681715
```ts
682-
import { signInWithRedirect } from "aws-amplify/auth"
716+
import { signInWithRedirect } from 'aws-amplify/auth';
683717

684-
signInWithRedirect({ provider: {
685-
custom: "MyOidcProvider"
686-
}})
718+
signInWithRedirect({
719+
provider: {
720+
custom: 'MyOidcProvider'
721+
}
722+
});
687723
```
688724

689725
### Auto sign-in
@@ -803,12 +839,12 @@ Future<void> socialSignIn() async {
803839
}
804840
}
805841
```
842+
806843
</InlineFilter>
807844
<InlineFilter filters={['android']}>
808845
## Update AndroidManifest.xml
809846

810-
Add the following activity and queries tag to your app's `AndroidManifest.xml` file, replacing `myapp` with
811-
your redirect URI prefix if necessary:
847+
Add the following activity and queries tag to your app's `AndroidManifest.xml` file, replacing `myapp` with your redirect URI prefix if necessary:
812848

813849
```xml
814850
<application ...>
@@ -892,8 +928,7 @@ RxAmplify.Auth.signInWithSocialWebUI(AuthProvider.facebook(), this)
892928
<InlineFilter filters={['swift']}>
893929
## Update Info.plist
894930

895-
Sign-in with web UI requires the Amplify plugin to show up the sign-in UI inside a webview. After the sign-in process is complete it will redirect back to your app.
896-
You have to enable this in your app's `Info.plist`. Right click Info.plist and then choose Open As > Source Code. Add the following entry in the URL scheme:
931+
Sign-in with web UI requires the Amplify plugin to show up the sign-in UI inside a webview. After the sign-in process is complete it will redirect back to your app. You have to enable this in your app's `Info.plist`. Right click Info.plist and then choose Open As > Source Code. Add the following entry in the URL scheme:
897932

898933
```xml
899934

0 commit comments

Comments
 (0)