Skip to content

Commit 85bb36b

Browse files
fix(settings): group connected services by deviceId to avoid sharing names
1 parent 13712ad commit 85bb36b

1 file changed

Lines changed: 12 additions & 14 deletions

File tree

  • packages/fxa-settings/src/components/Settings/ConnectedServices

packages/fxa-settings/src/components/Settings/ConnectedServices/index.tsx

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ const DEVICES_SUPPORT_URL =
2929
export function sortAndFilterConnectedClients(
3030
attachedClients: Array<AttachedClient>
3131
) {
32-
const groupedByName = groupBy(attachedClients, 'name');
32+
const groupedByDevice = groupBy(attachedClients, (c) => c.deviceId || c.name);
3333

34-
// get a unique (by name) list and sort by time last accessed
35-
const sortedAndUniqueClients = Object.keys(groupedByName)
34+
// get a unique (by device or name) list and sort by time last accessed
35+
const sortedAndUniqueClients = Object.keys(groupedByDevice)
3636
.map((key) => {
37-
return groupedByName[key].sort(
37+
return groupedByDevice[key].sort(
3838
(a: AttachedClient, b: AttachedClient) =>
3939
b.lastAccessTime - a.lastAccessTime
4040
)[0];
@@ -49,14 +49,14 @@ export function sortAndFilterConnectedClients(
4949
}
5050
});
5151

52-
return { groupedByName, sortedAndUniqueClients };
52+
return { groupedByDevice, sortedAndUniqueClients };
5353
}
5454

5555
export const ConnectedServices = forwardRef<HTMLDivElement>((_, ref) => {
5656
const alertBar = useAlertBar();
5757
const account = useAccount();
5858
const attachedClients = account.attachedClients;
59-
const { groupedByName, sortedAndUniqueClients } =
59+
const { groupedByDevice, sortedAndUniqueClients } =
6060
sortAndFilterConnectedClients([...attachedClients]);
6161

6262
const showMobilePromo = !sortedAndUniqueClients.filter(isMobileDevice).length;
@@ -107,14 +107,12 @@ export const ConnectedServices = forwardRef<HTMLDivElement>((_, ref) => {
107107
// disconnect all clients/sessions with this name since only unique names
108108
// are displayed to the user. This is batched into one network request
109109
// via BatchHttpLink
110-
const groupByKey = client.name ?? 'undefined';
111-
const clientsWithMatchingName = groupedByName[groupByKey];
112-
const hasMultipleSessions = clientsWithMatchingName.length > 1;
110+
const groupByKey = (client.deviceId || client.name) ?? 'undefined';
111+
const sessionsInGroup = groupedByDevice[groupByKey];
112+
const hasMultipleSessions = sessionsInGroup.length > 1;
113113
if (hasMultipleSessions) {
114114
await Promise.all(
115-
clientsWithMatchingName.map(
116-
async (c) => await account.disconnectClient(c)
117-
)
115+
sessionsInGroup.map(async (c) => await account.disconnectClient(c))
118116
);
119117
} else {
120118
await account.disconnectClient(client);
@@ -125,7 +123,7 @@ export const ConnectedServices = forwardRef<HTMLDivElement>((_, ref) => {
125123
if (
126124
client.isCurrentSession ||
127125
(hasMultipleSessions &&
128-
clientsWithMatchingName.find((c) => c.isCurrentSession))
126+
sessionsInGroup.find((c) => c.isCurrentSession))
129127
) {
130128
clearSignedInAccountUid();
131129
window.location.assign(`${window.location.origin}/signin`);
@@ -151,7 +149,7 @@ export const ConnectedServices = forwardRef<HTMLDivElement>((_, ref) => {
151149
[
152150
account,
153151
hideConfirmDisconnectModal,
154-
groupedByName,
152+
groupedByDevice,
155153
revealAdviceModal,
156154
alertBar,
157155
l10n,

0 commit comments

Comments
 (0)