UNPKG

2.75 kBTypeScriptView Raw
1import { AutoSignInCallback } from '../../../types/models';
2/**
3 * Signs a user in automatically after finishing the sign-up process.
4 *
5 * This API will automatically sign a user in if the autoSignIn flow has been completed in the following cases:
6 * - User confirmed their account with a verification code sent to their phone or email (default option).
7 * - User confirmed their account with a verification link sent to their phone or email. In order to
8 * enable this option you need to go to the Amazon Cognito [console](https://aws.amazon.com/pm/cognito),
9 * look for your userpool, then go to the `Messaging` tab and enable `link` mode inside the `Verification message` option.
10 * Finally you need to define the `signUpVerificationMethod` in your `Auth` config.
11 *
12 * @example
13 * ```typescript
14 * Amplify.configure({
15 * Auth: {
16 * Cognito: {
17 * ...cognitoConfig,
18 * signUpVerificationMethod: "link" // the default value is "code"
19 * }
20 * }});
21 * ```
22 *
23 * @throws AutoSignInException - Thrown when the autoSignIn flow has not started, or has been cancelled/completed.
24 * @returns The signInOutput.
25 *
26 * @example
27 * ```typescript
28 * // handleSignUp.ts
29 * async function handleSignUp(
30 * username:string,
31 * password:string
32 * ){
33 * try {
34 * const { nextStep } = await signUp({
35 * username,
36 * password,
37 * options: {
38 * userAttributes:{ email:'email@email.com'},
39 * autoSignIn: true // This enables the auto sign-in flow.
40 * },
41 * });
42 *
43 * handleSignUpStep(nextStep);
44 *
45 * } catch (error) {
46 * console.log(error);
47 * }
48 * }
49 *
50 * // handleConfirmSignUp.ts
51 * async function handleConfirmSignUp(username:string, confirmationCode:string) {
52 * try {
53 * const { nextStep } = await confirmSignUp({
54 * username,
55 * confirmationCode,
56 * });
57 *
58 * handleSignUpStep(nextStep);
59 * } catch (error) {
60 * console.log(error);
61 * }
62 * }
63 *
64 * // signUpUtils.ts
65 * async function handleSignUpStep( step: SignUpOutput["nextStep"]) {
66 * switch (step.signUpStep) {
67 * case "CONFIRM_SIGN_UP":
68 *
69 * // Redirect end-user to confirm-sign up screen.
70 *
71 * case "COMPLETE_AUTO_SIGN_IN":
72 * const codeDeliveryDetails = step.codeDeliveryDetails;
73 * if (codeDeliveryDetails) {
74 * // Redirect user to confirm-sign-up with link screen.
75 * }
76 * const signInOutput = await autoSignIn();
77 * // handle sign-in steps
78 * }
79 *
80 * ```
81 */
82export declare let autoSignIn: AutoSignInCallback;
83/**
84 * Sets the context of autoSignIn at run time.
85 * @internal
86 */
87export declare function setAutoSignIn(callback: AutoSignInCallback): void;
88/**
89 * Resets the context
90 *
91 * @internal
92 */
93export declare function resetAutoSignIn(): void;