Skip to content

Commit

Permalink
[native] allow password change only on primary device
Browse files Browse the repository at this point in the history
Summary:
This was discussed in [ENG-8070](https://linear.app/comm/issue/ENG-8070/regenerate-backup-on-every-password-change#comment-c64a499b)

Only the primary device should be able to change the password.

Perhaps there was some alternative to keep this for a while and disable this after the user migrated to Signed Device Lists (v2), but this is not easy and probably there is no need to complicate just to keep it for a ~month and then remove.

Hook with check was introduced in D14058

Depends on D14061, D14062

Test Plan:
1. On primary device button to change password is visible
2. On secondary device there is no button

Reviewers: ashoat, varun

Reviewed By: ashoat

Subscribers: tomek

Differential Revision: https://phab.comm.dev/D14063
  • Loading branch information
xsanm committed Dec 3, 2024
1 parent ff76ebb commit 99f4e4a
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions native/profile/profile-screen.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
useSecondaryDeviceLogOut,
} from 'lib/actions/user-actions.js';
import { useStringForUser } from 'lib/hooks/ens-cache.js';
import { useCheckIfPrimaryDevice } from 'lib/hooks/primary-device-hooks.js';
import { createLoadingStatusSelector } from 'lib/selectors/loading-selectors.js';
import { getOwnPrimaryDeviceID } from 'lib/selectors/user-selectors.js';
import { accountHasPassword } from 'lib/shared/account-utils.js';
import {
type OutboundDMOperationSpecification,
Expand All @@ -24,7 +24,6 @@ import type { LogOutResult } from 'lib/types/account-types.js';
import type { DMCreateThreadOperation } from 'lib/types/dm-ops';
import { thickThreadTypes } from 'lib/types/thread-types-enum.js';
import { type CurrentUserInfo } from 'lib/types/user-types.js';
import { getContentSigningKey } from 'lib/utils/crypto-utils.js';
import { useCurrentUserFID } from 'lib/utils/farcaster-utils.js';
import {
useDispatchActionPromise,
Expand Down Expand Up @@ -168,7 +167,7 @@ type BaseProps = {
type Props = {
...BaseProps,
+currentUserInfo: ?CurrentUserInfo,
+primaryDeviceID: ?string,
+isPrimaryDevice: boolean,
+logOutLoading: boolean,
+colors: Colors,
+styles: $ReadOnly<typeof unboundStyles>,
Expand Down Expand Up @@ -233,7 +232,10 @@ class ProfileScreen extends React.PureComponent<Props> {
}

let passwordEditionUI;
if (accountHasPassword(this.props.currentUserInfo)) {
if (
accountHasPassword(this.props.currentUserInfo) &&
this.props.isPrimaryDevice
) {
passwordEditionUI = (
<Action.Row>
<Text style={this.props.styles.label}>Password</Text>
Expand Down Expand Up @@ -412,12 +414,9 @@ class ProfileScreen extends React.PureComponent<Props> {
if (this.loggedOutOrLoggingOut) {
return;
}
const { primaryDeviceID } = this.props;
const currentDeviceID = await getContentSigningKey();
const isPrimaryDevice = currentDeviceID === primaryDeviceID;

let alertTitle, alertMessage, onPressAction;
if (isPrimaryDevice) {
if (this.props.isPrimaryDevice) {
alertTitle = 'Log out all devices?';
alertMessage =
'This device is your primary device, ' +
Expand Down Expand Up @@ -560,7 +559,6 @@ const logOutLoadingStatusSelector =
const ConnectedProfileScreen: React.ComponentType<BaseProps> =
React.memo<BaseProps>(function ConnectedProfileScreen(props: BaseProps) {
const currentUserInfo = useSelector(state => state.currentUserInfo);
const primaryDeviceID = useSelector(getOwnPrimaryDeviceID);
const logOutLoading =
useSelector(logOutLoadingStatusSelector) === 'loading';
const colors = useColors();
Expand All @@ -574,6 +572,8 @@ const ConnectedProfileScreen: React.ComponentType<BaseProps> =
accountHasPassword(state.currentUserInfo),
);
const currentUserID = useCurrentUserFID();
const [isPrimaryDevice, setIsPrimaryDevice] = React.useState(false);
const checkIfPrimaryDevice = useCheckIfPrimaryDevice();

const showVersionUnsupportedAlert = useShowVersionUnsupportedAlert(false);
const callLogOut = useLogOut({
Expand Down Expand Up @@ -607,11 +607,18 @@ const ConnectedProfileScreen: React.ComponentType<BaseProps> =
await processAndSendDMOperation(specification);
}, [processAndSendDMOperation, userID]);

React.useEffect(() => {
void (async () => {
const checkIfPrimaryDeviceResult = await checkIfPrimaryDevice();
setIsPrimaryDevice(checkIfPrimaryDeviceResult);
})();
}, [checkIfPrimaryDevice]);

return (
<ProfileScreen
{...props}
currentUserInfo={currentUserInfo}
primaryDeviceID={primaryDeviceID}
isPrimaryDevice={isPrimaryDevice}
logOutLoading={logOutLoading}
colors={colors}
styles={styles}
Expand Down

0 comments on commit 99f4e4a

Please sign in to comment.