diff --git a/packages/react/src/components/AccountSettings/ChangePassword/ChangePassword.tsx b/packages/react/src/components/AccountSettings/ChangePassword/ChangePassword.tsx index 0c6e018c750..d38ae1e451c 100644 --- a/packages/react/src/components/AccountSettings/ChangePassword/ChangePassword.tsx +++ b/packages/react/src/components/AccountSettings/ChangePassword/ChangePassword.tsx @@ -1,12 +1,12 @@ import React from 'react'; import isEqual from 'lodash/isEqual.js'; -import { ConsoleLogger as Logger } from '@aws-amplify/core/internals/utils'; import { changePassword, ValidatorOptions, getDefaultConfirmPasswordValidators, getDefaultPasswordValidators, + getLogger, runFieldValidators, } from '@aws-amplify/ui'; @@ -18,7 +18,7 @@ import { ChangePasswordProps, ValidateParams } from './types'; import DEFAULTS from './defaults'; import { defaultChangePasswordDisplayText } from '../utils'; -const logger = new Logger('ChangePassword'); +const logger = getLogger('ChangePassword'); const getIsDisabled = ( formValues: FormValues, @@ -173,7 +173,7 @@ function ChangePassword({ setErrorMessage(null); } - changePassword({ user, currentPassword, newPassword }) + changePassword({ currentPassword, newPassword }) .then(() => { // notify success to the parent onSuccess?.(); diff --git a/packages/react/src/components/AccountSettings/ChangePassword/__tests__/ChangePassword.test.tsx b/packages/react/src/components/AccountSettings/ChangePassword/__tests__/ChangePassword.test.tsx index 995ac607d39..5f788c575a8 100644 --- a/packages/react/src/components/AccountSettings/ChangePassword/__tests__/ChangePassword.test.tsx +++ b/packages/react/src/components/AccountSettings/ChangePassword/__tests__/ChangePassword.test.tsx @@ -98,7 +98,6 @@ describe('ChangePassword', () => { fireEvent.submit(submitButton); expect(changePasswordSpy).toBeCalledWith({ - user, currentPassword: 'oldpassword', newPassword: 'newpassword', }); @@ -343,7 +342,6 @@ describe('ChangePassword', () => { fireEvent.submit(submitButton); expect(changePasswordSpy).toBeCalledWith({ - user, currentPassword: 'oldpassword', newPassword: 'newpassword', }); diff --git a/packages/ui/src/helpers/accountSettings/__tests__/utils.test.ts b/packages/ui/src/helpers/accountSettings/__tests__/utils.test.ts index 5c38b360223..44125e551e3 100644 --- a/packages/ui/src/helpers/accountSettings/__tests__/utils.test.ts +++ b/packages/ui/src/helpers/accountSettings/__tests__/utils.test.ts @@ -1,46 +1,42 @@ -import * as Auth from '@aws-amplify/auth'; +import * as Auth from 'aws-amplify/auth'; import { changePassword, deleteUser } from '../utils'; -import { AmplifyUser } from '../../../types'; // mock `aws-amplify` to prevent logging auth errors during test runs jest.mock('aws-amplify'); -const changePasswordSpy = jest.spyOn(Auth, 'changePassword'); +const changePasswordSpy = jest.spyOn(Auth, 'updatePassword'); const deleteUserSpy = jest.spyOn(Auth, 'deleteUser'); describe('changePassword', () => { - const user = { username: 'testuser' } as AmplifyUser; const currentPassword = 'oldpassword'; const newPassword = 'newpassword'; - it('should resolve if Auth.changePassword is successful', async () => { - changePasswordSpy.mockResolvedValue('SUCCESS'); + it('should resolve if Auth.updatePassword is successful', async () => { + changePasswordSpy.mockResolvedValue(); await expect( - changePassword({ user, currentPassword, newPassword }) + changePassword({ currentPassword, newPassword }) ).resolves.toBeUndefined(); - expect(changePasswordSpy).toHaveBeenCalledWith( - user, - currentPassword, - newPassword - ); + expect(changePasswordSpy).toHaveBeenCalledWith({ + newPassword: newPassword, + oldPassword: currentPassword, + }); }); - it('should reject with error if Auth.changePassword fails', async () => { + it('should reject with error if Auth.updatePassword fails', async () => { const error = new Error('change password failed'); changePasswordSpy.mockRejectedValue(error); await expect( - changePassword({ user, currentPassword, newPassword }) + changePassword({ currentPassword, newPassword }) ).rejects.toEqual(error); - expect(changePasswordSpy).toHaveBeenCalledWith( - user, - currentPassword, - newPassword - ); + expect(changePasswordSpy).toHaveBeenCalledWith({ + newPassword: newPassword, + oldPassword: currentPassword, + }); }); }); diff --git a/packages/ui/src/helpers/accountSettings/utils.ts b/packages/ui/src/helpers/accountSettings/utils.ts index 8089cee3cfc..b848c901a97 100644 --- a/packages/ui/src/helpers/accountSettings/utils.ts +++ b/packages/ui/src/helpers/accountSettings/utils.ts @@ -1,37 +1,32 @@ -import * as Auth from '@aws-amplify/auth'; +import { updatePassword, deleteUser as deleteAuthUser } from 'aws-amplify/auth'; -import { AmplifyUser } from '../../types'; import { getLogger } from '../utils'; const logger = getLogger('Auth'); type ChangePasswordInput = { - user: AmplifyUser; currentPassword: string; newPassword: string; }; export const changePassword = async ({ - user: _, currentPassword, newPassword, }: ChangePasswordInput): Promise => { try { - logger.debug('calling Auth.changePassword'); + logger.debug('calling Auth.updatePassword'); /** - * Auth.changePassword returns `Promise<"SUCCESS">`. We're not interested + * Auth.updatePassword returns `Promise<"SUCCESS">`. We're not interested * in its resolved string value, so we just return Promise.resolve() on success. */ - // await Auth.changePassword(user, currentPassword, newPassword); - const input: Auth.UpdatePasswordInput = { + await updatePassword({ oldPassword: currentPassword, newPassword, - }; - await Auth.updatePassword(input); - logger.debug('Auth.changePassword was successful'); + }); + logger.debug('Auth.updatePassword was successful'); return Promise.resolve(); } catch (e) { - logger.debug('Auth.changePassword failed with error', e); + logger.debug('Auth.updatePassword failed with error', e); return Promise.reject(e); } }; @@ -40,7 +35,7 @@ export const deleteUser = async () => { try { logger.debug('calling Auth.deleteUser'); await Promise.resolve(); - // await Auth.deleteUser(); + await deleteAuthUser(); logger.debug('Auth.deleteUser was successful'); return Promise.resolve(); } catch (e) { diff --git a/yarn.lock b/yarn.lock index 4df8bf390a7..b3b63e2e6df 100644 --- a/yarn.lock +++ b/yarn.lock @@ -434,50 +434,50 @@ resolved "https://registry.npmjs.org/@assemblyscript/loader/-/loader-0.10.1.tgz#70e45678f06c72fa2e350e8553ec4a4d72b92e06" integrity sha512-H71nDOOL8Y7kWRLqf6Sums+01Q5msqBW2KhDUTemh1tvY04eSkSXrK0uj/4mmY0Xr16/3zyZmsrxN7CKuRbNRg== -"@aws-amplify/analytics@7.0.1-console-preview.deaebd5.0+deaebd5": - version "7.0.1-console-preview.deaebd5.0" - resolved "https://registry.npmjs.org/@aws-amplify/analytics/-/analytics-7.0.1-console-preview.deaebd5.0.tgz#967a6c17379f38bf71584a1ba29368e65289c824" - integrity sha512-Zutu0Kgxu6HBLZfQI/YJG1GF7oK/KpOOWCizDQGCC6WN/ZNFW9NNcFjP3dKev5HSQatk4d2lbwrtSdaH2yJHjg== +"@aws-amplify/analytics@7.0.1-console-preview.11cf989.0+11cf989": + version "7.0.1-console-preview.11cf989.0" + resolved "https://registry.yarnpkg.com/@aws-amplify/analytics/-/analytics-7.0.1-console-preview.11cf989.0.tgz#66f5b42e73245107afca344f4a56098195ee2f6e" + integrity sha512-Pf8IXd6RLJpE3/sBAno/gAfAIeS1jaycbr7t4OCrnoS/MYH/nDF/tNLy7OrkRFwFKx5WT5eB4GUL8emI5Mf6Iw== dependencies: tslib "^2.5.0" uuid "^9.0.0" -"@aws-amplify/api-graphql@4.0.1-console-preview.deaebd5.0+deaebd5": - version "4.0.1-console-preview.deaebd5.0" - resolved "https://registry.npmjs.org/@aws-amplify/api-graphql/-/api-graphql-4.0.1-console-preview.deaebd5.0.tgz#7e0ad217808ce2cb06ad62c65cab572969efc8bb" - integrity sha512-O0hvmzfankN2HXqyVpnVFzcFE7DE+LcviSDVlQi5H29S9SrSjHo+vYtlM7LXvKIjgupiE7lUUYuCknBLImeXdg== +"@aws-amplify/api-graphql@4.0.1-console-preview.11cf989.0+11cf989": + version "4.0.1-console-preview.11cf989.0" + resolved "https://registry.yarnpkg.com/@aws-amplify/api-graphql/-/api-graphql-4.0.1-console-preview.11cf989.0.tgz#1aec359cb48bb09d8c56f87542817673451d3d19" + integrity sha512-J87mTwVjze+XlwAqfWnxGVRpRXqcZJ2v2DOE1Yh4BWuGRDfyNa0zMt8pMtIFXjkoDDOgez/5nWzAJXZsHjZDWQ== dependencies: - "@aws-amplify/api-rest" "4.0.1-console-preview.deaebd5.0+deaebd5" - "@aws-amplify/auth" "6.0.1-console-preview.deaebd5.0+deaebd5" - "@aws-amplify/core" "6.0.1-console-preview.deaebd5.0+deaebd5" + "@aws-amplify/api-rest" "4.0.1-console-preview.11cf989.0+11cf989" + "@aws-amplify/auth" "6.0.1-console-preview.11cf989.0+11cf989" + "@aws-amplify/core" "6.0.1-console-preview.11cf989.0+11cf989" "@aws-sdk/types" "3.387.0" graphql "15.8.0" rxjs "^7.8.1" tslib "^1.8.0" uuid "^3.2.1" -"@aws-amplify/api-rest@4.0.1-console-preview.deaebd5.0+deaebd5": - version "4.0.1-console-preview.deaebd5.0" - resolved "https://registry.npmjs.org/@aws-amplify/api-rest/-/api-rest-4.0.1-console-preview.deaebd5.0.tgz#d1b7bb14234704a6b357057e5e36c9ec5e8cefd7" - integrity sha512-kP/X4TAOzntP2C68pE2whIRO0STw6xhA/ZzQlxSJet2JC2qQJGsdp1q4gSjSr7t0jIE6lHAlE+eFCKbU/7nxlA== +"@aws-amplify/api-rest@4.0.1-console-preview.11cf989.0+11cf989": + version "4.0.1-console-preview.11cf989.0" + resolved "https://registry.yarnpkg.com/@aws-amplify/api-rest/-/api-rest-4.0.1-console-preview.11cf989.0.tgz#47c90f32cc7a0308ec0d8d6c4e667d1b1975baae" + integrity sha512-+sxrDjVOdJI5Ra4Gz0Bu5QN+FDt3fcTgVR+Xpp4rXTLn2FMRHzrG3b9ZlwkkLPPcLZUG31qdiJQXhf1r+RYJtg== dependencies: axios "0.26.0" tslib "^2.5.0" url "0.11.0" -"@aws-amplify/api@6.0.1-console-preview.deaebd5.0+deaebd5": - version "6.0.1-console-preview.deaebd5.0" - resolved "https://registry.npmjs.org/@aws-amplify/api/-/api-6.0.1-console-preview.deaebd5.0.tgz#9c7cbf6338b795340bbf5413d4a82914c5603806" - integrity sha512-BHlTzo9DQpp4rE+XliQERlcJlB9g/l153vBTdjQtbAh5uy1efQUDrINPQ6CXZkhOj5CaW/QIWma3l630PYzm4A== +"@aws-amplify/api@6.0.1-console-preview.11cf989.0+11cf989": + version "6.0.1-console-preview.11cf989.0" + resolved "https://registry.yarnpkg.com/@aws-amplify/api/-/api-6.0.1-console-preview.11cf989.0.tgz#7e4d17d8a653fd804adb8b4db428969f6eb0c7ba" + integrity sha512-V4MaKkXWuDL4DaJcuPIeYZDSHDKPI7Hg+SfOQ6PBvZlG6ZTgq8d1PgnyuqZwv0HZs5vxOr+dOe3MGfgs4BIOXg== dependencies: - "@aws-amplify/api-graphql" "4.0.1-console-preview.deaebd5.0+deaebd5" - "@aws-amplify/api-rest" "4.0.1-console-preview.deaebd5.0+deaebd5" + "@aws-amplify/api-graphql" "4.0.1-console-preview.11cf989.0+11cf989" + "@aws-amplify/api-rest" "4.0.1-console-preview.11cf989.0+11cf989" tslib "^2.6.1" -"@aws-amplify/auth@6.0.1-console-preview.deaebd5.0+deaebd5": - version "6.0.1-console-preview.deaebd5.0" - resolved "https://registry.npmjs.org/@aws-amplify/auth/-/auth-6.0.1-console-preview.deaebd5.0.tgz#87efd6aa839a935d1a5069c8e5968cf02b9284cd" - integrity sha512-65flKbfMgz9u/iB/fy62dciF/vlbIC3z5b2D75r9AB2HJ3pxDv5zU43Ylbl3iwehOGRheWdhunIVlzr8NBKdaw== +"@aws-amplify/auth@6.0.1-console-preview.11cf989.0+11cf989": + version "6.0.1-console-preview.11cf989.0" + resolved "https://registry.yarnpkg.com/@aws-amplify/auth/-/auth-6.0.1-console-preview.11cf989.0.tgz#5a469ef7cdb23051490ef2b254b6992d37c47d02" + integrity sha512-ipyKhaS6cCs5eHzcX/Qa/glfzhfioyWNn+dHl0MCpemBfaU7AauArGtp5nKsW4qdUo6C8uNcgI4wrF/8v3XRtQ== dependencies: tslib "^2.5.0" typescript "5.0.2" @@ -506,10 +506,10 @@ universal-cookie "^4.0.4" zen-observable-ts "0.8.19" -"@aws-amplify/core@6.0.1-console-preview.deaebd5.0+deaebd5": - version "6.0.1-console-preview.deaebd5.0" - resolved "https://registry.npmjs.org/@aws-amplify/core/-/core-6.0.1-console-preview.deaebd5.0.tgz#d0e21b4d24466fbeb6fd4c15355fe18043673076" - integrity sha512-kxlYIB7h9PV+I3qMZ/VuzflGKZk+jlc2GzpOiBjSaba3kR65w2v5ixI+3kXXRUtwJWHm/k451We2J1Y6vmOz5Q== +"@aws-amplify/core@6.0.1-console-preview.11cf989.0+11cf989": + version "6.0.1-console-preview.11cf989.0" + resolved "https://registry.yarnpkg.com/@aws-amplify/core/-/core-6.0.1-console-preview.11cf989.0.tgz#7c4ffdd5b4ea2b98d48fd41c489309f9dbd5e5a3" + integrity sha512-SPul4oA4geJCWsbFFZF5LOKtLpDAOQ3vhgkEocTk250s8evTAl5iq3E7RIE/cFFxbesPTmF1VVeKMtN9Yx+5DA== dependencies: "@aws-crypto/sha256-js" "5.0.0" "@aws-sdk/types" "3.398.0" @@ -519,13 +519,13 @@ tslib "^2.5.0" uuid "^9.0.0" -"@aws-amplify/datastore@5.0.1-console-preview.deaebd5.0+deaebd5": - version "5.0.1-console-preview.deaebd5.0" - resolved "https://registry.npmjs.org/@aws-amplify/datastore/-/datastore-5.0.1-console-preview.deaebd5.0.tgz#5f25c174305fca4bfcd318633c8d83ea6cbf3be0" - integrity sha512-BLV8O7IOeRcKaSh1gL3XrcbsmEboFf56fPfj5XbOyg/g2hU0ryKvnhtGvaTrC+e25EWB/RL1RnacnTbnYEkZ4g== +"@aws-amplify/datastore@5.0.1-console-preview.11cf989.0+11cf989": + version "5.0.1-console-preview.11cf989.0" + resolved "https://registry.yarnpkg.com/@aws-amplify/datastore/-/datastore-5.0.1-console-preview.11cf989.0.tgz#c6498747288c0be6c36dfc965b82924e5d18dd1b" + integrity sha512-JqLWkGg4EwFZSwGeT1O2wgFgfu4iOYZS5M8JoYMmI1d8UeN5nnDI68V0KFAMEkaXBF3Tv7tdSjbB/MTjzwFVXg== dependencies: - "@aws-amplify/api" "6.0.1-console-preview.deaebd5.0+deaebd5" - "@aws-amplify/auth" "6.0.1-console-preview.deaebd5.0+deaebd5" + "@aws-amplify/api" "6.0.1-console-preview.11cf989.0+11cf989" + "@aws-amplify/auth" "6.0.1-console-preview.11cf989.0+11cf989" buffer "4.9.2" idb "5.0.6" immer "9.0.6" @@ -560,10 +560,10 @@ resolved "https://registry.npmjs.org/@aws-amplify/rtn-push-notification/-/rtn-push-notification-1.1.7.tgz#90593b613db4ee935ff5208c012cc7b6524be2fc" integrity sha512-P3Gj0o5g6DZoSdN3DXDweOU2on8eZKr/KzbX1beCaNgBnjqGW0pIkMvD+SMdffXeRD0Lbawk9FHvQM7o0BwR8g== -"@aws-amplify/storage@6.0.1-console-preview.deaebd5.0+deaebd5": - version "6.0.1-console-preview.deaebd5.0" - resolved "https://registry.npmjs.org/@aws-amplify/storage/-/storage-6.0.1-console-preview.deaebd5.0.tgz#87668b14293aa4b919af5d74d1d2b21e7d76f003" - integrity sha512-nZrkVcFkWKpHAoPXy0P/jCT9ZS3WuU50YGHSt4k45tRyEMYthuswTT+DTx6E0O2xkDZ+1mj4X4N/W3zAq01WpQ== +"@aws-amplify/storage@6.0.1-console-preview.11cf989.0+11cf989": + version "6.0.1-console-preview.11cf989.0" + resolved "https://registry.yarnpkg.com/@aws-amplify/storage/-/storage-6.0.1-console-preview.11cf989.0.tgz#d357e5ea51eac917dc56d1b15644ee6f59bb57c2" + integrity sha512-LjDJqAOPMUErQJ/cWG55Cw6htzFPDmqOHZFKRLbzUjamsltLBFi3iM0SgTNGvXPNxPFEsiYgLZCNr4q9FEMIUQ== dependencies: "@aws-sdk/types" "3.398.0" "@smithy/md5-js" "2.0.7" @@ -11099,16 +11099,16 @@ available-typed-arrays@^1.0.5: integrity sha512-DMD0KiN46eipeziST1LPP/STfDU0sufISXmjSgvVsoU2tqxctQeASejWcfNtxYKqETM1UxQ8sp2OrSBWpHY6sw== aws-amplify@console-preview: - version "6.0.1-console-preview.deaebd5.0" - resolved "https://registry.npmjs.org/aws-amplify/-/aws-amplify-6.0.1-console-preview.deaebd5.0.tgz#a112c7576fd59d47ccb692dd60e4561f1e268018" - integrity sha512-3shA+JzhV0SCqLMFvBNjjuv9PalYRaHvl285A+bxN1P2QE2BSXZCdvC40NEkyYfUf/cws9dc8DUtMumExgrHfw== - dependencies: - "@aws-amplify/analytics" "7.0.1-console-preview.deaebd5.0+deaebd5" - "@aws-amplify/api" "6.0.1-console-preview.deaebd5.0+deaebd5" - "@aws-amplify/auth" "6.0.1-console-preview.deaebd5.0+deaebd5" - "@aws-amplify/core" "6.0.1-console-preview.deaebd5.0+deaebd5" - "@aws-amplify/datastore" "5.0.1-console-preview.deaebd5.0+deaebd5" - "@aws-amplify/storage" "6.0.1-console-preview.deaebd5.0+deaebd5" + version "6.0.1-console-preview.11cf989.0" + resolved "https://registry.yarnpkg.com/aws-amplify/-/aws-amplify-6.0.1-console-preview.11cf989.0.tgz#e33ba277c6b0285469de6599242294f7f1625d14" + integrity sha512-LIrR5aOv4OnDRGUgizsmVYeisCoRMYYXZFzcZbRcMF6t15Knj0UGjg/KBvXE+Ro0gYwnqxy5V34NaxZZrKyKFw== + dependencies: + "@aws-amplify/analytics" "7.0.1-console-preview.11cf989.0+11cf989" + "@aws-amplify/api" "6.0.1-console-preview.11cf989.0+11cf989" + "@aws-amplify/auth" "6.0.1-console-preview.11cf989.0+11cf989" + "@aws-amplify/core" "6.0.1-console-preview.11cf989.0+11cf989" + "@aws-amplify/datastore" "5.0.1-console-preview.11cf989.0+11cf989" + "@aws-amplify/storage" "6.0.1-console-preview.11cf989.0+11cf989" tslib "^2.5.0" aws-crt@^1.10.6: @@ -27340,7 +27340,7 @@ semver@7.3.8, semver@7.5.4, semver@7.x, semver@^7.0.0, semver@^7.1.1, semver@^7. semver@7.5.3: version "7.5.3" - resolved "https://registry.npmjs.org/semver/-/semver-7.5.3.tgz#161ce8c2c6b4b3bdca6caadc9fa3317a4c4fe88e" + resolved "https://registry.yarnpkg.com/semver/-/semver-7.5.3.tgz#161ce8c2c6b4b3bdca6caadc9fa3317a4c4fe88e" integrity sha512-QBlUtyVk/5EeHbi7X0fw6liDZc7BBmEaSYn01fMU1OUYbf6GPsbTtd8WmnqbI20SeycoHSeiybkE/q1Q+qlThQ== dependencies: lru-cache "^6.0.0"