{"version":3,"file":"autoSignIn.mjs","sources":["../../../../../src/providers/cognito/apis/autoSignIn.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { autoSignInStore } from '../../../client/utils/store';\nimport { AuthError } from '../../../errors/AuthError';\nimport { AUTO_SIGN_IN_EXCEPTION } from '../../../errors/constants';\nconst initialAutoSignIn = async () => {\n    throw new AuthError({\n        name: AUTO_SIGN_IN_EXCEPTION,\n        message: 'The autoSignIn flow has not started, or has been cancelled/completed.',\n        recoverySuggestion: 'Please try to use the signIn API or log out before starting a new autoSignIn flow.',\n    });\n};\n/**\n * Signs a user in automatically after finishing the sign-up process.\n *\n * This API will automatically sign a user in if the autoSignIn flow has been completed in the following cases:\n * - User confirmed their account with a verification code sent to their phone or email (default option).\n * - User confirmed their account with a verification link sent to their phone or email. In order to\n * enable this option you need to go to the Amazon Cognito [console](https://aws.amazon.com/pm/cognito),\n * look for your userpool, then go to the `Messaging` tab and enable `link` mode inside the `Verification message` option.\n * Finally you need to define the `signUpVerificationMethod` in your `Auth` config.\n *\n * @example\n * ```typescript\n *  Amplify.configure({\n *    Auth: {\n *     Cognito: {\n *    ...cognitoConfig,\n *    signUpVerificationMethod: \"link\" // the default value is \"code\"\n *   }\n *\t}});\n * ```\n *\n * @throws AutoSignInException - Thrown when the autoSignIn flow has not started, or has been cancelled/completed.\n * @returns The signInOutput.\n *\n * @example\n * ```typescript\n *  // handleSignUp.ts\n * async function handleSignUp(\n *   username:string,\n *   password:string\n * ){\n *   try {\n *     const { nextStep } = await signUp({\n *       username,\n *       password,\n *       options: {\n *         userAttributes:{ email:'email@email.com'},\n *         autoSignIn: true // This enables the auto sign-in flow.\n *       },\n *     });\n *\n *     handleSignUpStep(nextStep);\n *\n *   } catch (error) {\n *     console.log(error);\n *   }\n * }\n *\n * // handleConfirmSignUp.ts\n * async function handleConfirmSignUp(username:string, confirmationCode:string) {\n *   try {\n *     const { nextStep } = await confirmSignUp({\n *       username,\n *       confirmationCode,\n *     });\n *\n *     handleSignUpStep(nextStep);\n *   } catch (error) {\n *     console.log(error);\n *   }\n * }\n *\n * // signUpUtils.ts\n * async function handleSignUpStep( step: SignUpOutput[\"nextStep\"]) {\n * switch (step.signUpStep) {\n *   case \"CONFIRM_SIGN_UP\":\n *\n *    // Redirect end-user to confirm-sign up screen.\n *\n *   case \"COMPLETE_AUTO_SIGN_IN\":\n *\t   const codeDeliveryDetails = step.codeDeliveryDetails;\n *     if (codeDeliveryDetails) {\n *      // Redirect user to confirm-sign-up with link screen.\n *     }\n *     const signInOutput = await autoSignIn();\n *   // handle sign-in steps\n * }\n *\n * ```\n */\n// TODO(Eslint): can this be refactored not using `let` on exported member?\n// eslint-disable-next-line import/no-mutable-exports\nexport let autoSignIn = initialAutoSignIn;\n/**\n * Sets the context of autoSignIn at run time.\n * @internal\n */\nexport function setAutoSignIn(callback) {\n    autoSignIn = callback;\n}\n/**\n * Resets the context\n *\n * @internal\n */\nexport function resetAutoSignIn(resetCallback = true) {\n    if (resetCallback) {\n        autoSignIn = initialAutoSignIn;\n    }\n    autoSignInStore.dispatch({ type: 'RESET' });\n}\n"],"names":[],"mappings":";;;;;AAAA;AACA;AAIA,MAAM,iBAAiB,GAAG,YAAY;AACtC,IAAI,MAAM,IAAI,SAAS,CAAC;AACxB,QAAQ,IAAI,EAAE,sBAAsB;AACpC,QAAQ,OAAO,EAAE,uEAAuE;AACxF,QAAQ,kBAAkB,EAAE,oFAAoF;AAChH,KAAK,CAAC;AACN,CAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACU,IAAC,UAAU,GAAG;AACxB;AACA;AACA;AACA;AACO,SAAS,aAAa,CAAC,QAAQ,EAAE;AACxC,IAAI,UAAU,GAAG,QAAQ;AACzB;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,eAAe,CAAC,aAAa,GAAG,IAAI,EAAE;AACtD,IAAI,IAAI,aAAa,EAAE;AACvB,QAAQ,UAAU,GAAG,iBAAiB;AACtC,IAAI;AACJ,IAAI,eAAe,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;AAC/C;;;;"}