Skip to content

Commit 96fdca9

Browse files
authored
Merge pull request #127 from michaelkamphausen/feature/remove-device-using-deviceid
auth: using deviceId instead of deviceName to identify a device
2 parents 23f11af + 1b0df8e commit 96fdca9

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

packages/auth/src/team/test/devices.test.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { redactDevice } from 'index.js'
1+
import { createDevice, redactDevice } from 'index.js'
22
import { setup as setupUsers } from 'util/testing/index.js'
33
import { describe, expect, it } from 'vitest'
44

@@ -41,6 +41,26 @@ describe('Team', () => {
4141
expect(tryToRemoveDevice).toThrowError()
4242
})
4343

44+
it("doesn't remove other devices with the same name", () => {
45+
const { alice } = setup()
46+
47+
// Alice already has a device called 'laptop'
48+
const firstLaptop = alice.device
49+
expect(firstLaptop.deviceName).toBe('laptop')
50+
expect(alice.team.members(alice.userId).devices).toHaveLength(1)
51+
52+
// Alice adds a second device also called 'laptop'
53+
const secondLaptop = createDevice({ userId: alice.userId, deviceName: 'laptop' })
54+
alice.team.addForTesting(alice.user, [], redactDevice(secondLaptop))
55+
expect(alice.team.members(alice.userId).devices).toHaveLength(2)
56+
57+
// Alice removes the first laptop
58+
alice.team.removeDevice(alice.device.deviceId)
59+
60+
// The second laptop is still there
61+
expect(alice.team.members(alice.userId).devices).toHaveLength(1)
62+
})
63+
4464
it('deviceWasRemoved works as expected', () => {
4565
const { alice, bob } = setup()
4666
alice.team.removeDevice(bob.device.deviceId)

packages/auth/src/team/transforms/removeDevice.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const removeDevice =
1212
member.userId === userId
1313
? {
1414
...member,
15-
devices: member.devices?.filter(d => d.deviceName !== removedDevice.deviceName),
15+
devices: member.devices?.filter(d => d.deviceId !== removedDevice.deviceId),
1616
}
1717
: member
1818

packages/auth/src/util/actionFingerprint.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const actionFingerprint = (link: TeamLink) => {
2525
}
2626

2727
case 'ADD_DEVICE': {
28-
return action.payload.device.deviceName
28+
return action.payload.device.deviceId
2929
}
3030

3131
case 'REMOVE_DEVICE': {

0 commit comments

Comments
 (0)