@aws-amplify/auth
Version:
Auth category of aws-amplify
1 lines • 2.87 kB
Source Map (JSON)
{"version":3,"file":"updatePassword.mjs","sources":["../../../../../src/providers/cognito/apis/updatePassword.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { Amplify, fetchAuthSession } from '@aws-amplify/core';\nimport { AuthAction, assertTokenProviderConfig, } from '@aws-amplify/core/internals/utils';\nimport { AuthValidationErrorCode } from '../../../errors/types/validation';\nimport { assertValidationError } from '../../../errors/utils/assertValidationError';\nimport { changePassword } from '../utils/clients/CognitoIdentityProvider';\nimport { getRegion } from '../utils/clients/CognitoIdentityProvider/utils';\nimport { assertAuthTokens } from '../utils/types';\nimport { getAuthUserAgentValue } from '../../../utils';\n/**\n * Updates user's password while authenticated.\n *\n * @param input - The UpdatePasswordInput object.\n * @throws - {@link ChangePasswordException} - Cognito service errors thrown when updating a password.\n * @throws - {@link AuthValidationErrorCode} - Validation errors thrown when oldPassword or newPassword are empty.\n * @throws AuthTokenConfigException - Thrown when the token provider config is invalid.\n */\nexport async function updatePassword(input) {\n const authConfig = Amplify.getConfig().Auth?.Cognito;\n assertTokenProviderConfig(authConfig);\n const { oldPassword, newPassword } = input;\n assertValidationError(!!oldPassword, AuthValidationErrorCode.EmptyUpdatePassword);\n assertValidationError(!!newPassword, AuthValidationErrorCode.EmptyUpdatePassword);\n const { tokens } = await fetchAuthSession({ forceRefresh: false });\n assertAuthTokens(tokens);\n await changePassword({\n region: getRegion(authConfig.userPoolId),\n userAgentValue: getAuthUserAgentValue(AuthAction.UpdatePassword),\n }, {\n AccessToken: tokens.accessToken.toString(),\n PreviousPassword: oldPassword,\n ProposedPassword: newPassword,\n });\n}\n"],"names":[],"mappings":";;;;;;;;;AAAA;AACA;AASA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,eAAe,cAAc,CAAC,KAAK,EAAE;AAC5C,IAAI,MAAM,UAAU,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC;AACzD,IAAI,yBAAyB,CAAC,UAAU,CAAC,CAAC;AAC1C,IAAI,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,GAAG,KAAK,CAAC;AAC/C,IAAI,qBAAqB,CAAC,CAAC,CAAC,WAAW,EAAE,uBAAuB,CAAC,mBAAmB,CAAC,CAAC;AACtF,IAAI,qBAAqB,CAAC,CAAC,CAAC,WAAW,EAAE,uBAAuB,CAAC,mBAAmB,CAAC,CAAC;AACtF,IAAI,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,gBAAgB,CAAC,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC,CAAC;AACvE,IAAI,gBAAgB,CAAC,MAAM,CAAC,CAAC;AAC7B,IAAI,MAAM,cAAc,CAAC;AACzB,QAAQ,MAAM,EAAE,SAAS,CAAC,UAAU,CAAC,UAAU,CAAC;AAChD,QAAQ,cAAc,EAAE,qBAAqB,CAAC,UAAU,CAAC,cAAc,CAAC;AACxE,KAAK,EAAE;AACP,QAAQ,WAAW,EAAE,MAAM,CAAC,WAAW,CAAC,QAAQ,EAAE;AAClD,QAAQ,gBAAgB,EAAE,WAAW;AACrC,QAAQ,gBAAgB,EAAE,WAAW;AACrC,KAAK,CAAC,CAAC;AACP;;;;"}