diff --git a/native/profile/edit-password.react.js b/native/profile/edit-password.react.js --- a/native/profile/edit-password.react.js +++ b/native/profile/edit-password.react.js @@ -14,15 +14,19 @@ import { changeKeyserverUserPasswordActionTypes, changeKeyserverUserPassword, + useChangeIdentityUserPassword, + changeIdentityUserPasswordActionTypes, } from 'lib/actions/user-actions.js'; import { useLegacyAshoatKeyserverCall } from 'lib/keyserver-conn/legacy-keyserver-call.js'; import { createLoadingStatusSelector } from 'lib/selectors/loading-selectors.js'; import type { LoadingStatus } from 'lib/types/loading-types.js'; import type { PasswordUpdate } from 'lib/types/user-types.js'; +import { getMessageForException } from 'lib/utils/errors.js'; import { useDispatchActionPromise, type DispatchActionPromise, } from 'lib/utils/redux-promise-utils.js'; +import { usingCommServicesAccessToken } from 'lib/utils/services-utils.js'; import type { ProfileNavigationProp } from './profile.react.js'; import { setNativeCredentials } from '../account/native-credentials.js'; @@ -107,6 +111,10 @@ +changeKeyserverUserPassword: ( passwordUpdate: PasswordUpdate, ) => Promise, + +changeIdentityUserPassword: ( + oldPassword: string, + newPassword: string, + ) => Promise, }; type State = { +currentPassword: string, @@ -276,6 +284,11 @@ ); } else if (this.state.newPassword === this.state.currentPassword) { this.goBackOnce(); + } else if (usingCommServicesAccessToken) { + void this.props.dispatchActionPromise( + changeIdentityUserPasswordActionTypes, + this.savePassword(), + ); } else { void this.props.dispatchActionPromise( changeKeyserverUserPasswordActionTypes, @@ -290,19 +303,30 @@ return; } try { - await this.props.changeKeyserverUserPassword({ - updatedFields: { - password: this.state.newPassword, - }, - currentPassword: this.state.currentPassword, - }); + if (usingCommServicesAccessToken) { + await this.props.changeIdentityUserPassword( + this.state.currentPassword, + this.state.newPassword, + ); + } else { + await this.props.changeKeyserverUserPassword({ + updatedFields: { + password: this.state.newPassword, + }, + currentPassword: this.state.currentPassword, + }); + } await setNativeCredentials({ username, password: this.state.newPassword, }); this.goBackOnce(); } catch (e) { - if (e.message === 'invalid_credentials') { + const messageForException = getMessageForException(e); + if ( + messageForException === 'invalid_credentials' || + messageForException === 'login_failed' + ) { Alert.alert( 'Incorrect password', 'The current password you entered is incorrect', @@ -339,9 +363,9 @@ }; } -const loadingStatusSelector = createLoadingStatusSelector( - changeKeyserverUserPasswordActionTypes, -); +const loadingStatusSelector = usingCommServicesAccessToken + ? createLoadingStatusSelector(changeIdentityUserPasswordActionTypes) + : createLoadingStatusSelector(changeKeyserverUserPasswordActionTypes); const ConnectedEditPassword: React.ComponentType = React.memo(function ConnectedEditPassword(props: BaseProps) { @@ -359,6 +383,7 @@ const callChangeKeyserverUserPassword = useLegacyAshoatKeyserverCall( changeKeyserverUserPassword, ); + const callChangeIdentityUserPassword = useChangeIdentityUserPassword(); return ( ); });