Skip to content

Commit

Permalink
Merge pull request #127 from michaelkamphausen/feature/remove-device-…
Browse files Browse the repository at this point in the history
…using-deviceid

auth: using deviceId instead of deviceName to identify a device
  • Loading branch information
HerbCaudill authored Sep 24, 2024
2 parents 23f11af + 1b0df8e commit 96fdca9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
22 changes: 21 additions & 1 deletion packages/auth/src/team/test/devices.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { redactDevice } from 'index.js'
import { createDevice, redactDevice } from 'index.js'
import { setup as setupUsers } from 'util/testing/index.js'
import { describe, expect, it } from 'vitest'

Expand Down Expand Up @@ -41,6 +41,26 @@ describe('Team', () => {
expect(tryToRemoveDevice).toThrowError()
})

it("doesn't remove other devices with the same name", () => {
const { alice } = setup()

// Alice already has a device called 'laptop'
const firstLaptop = alice.device
expect(firstLaptop.deviceName).toBe('laptop')
expect(alice.team.members(alice.userId).devices).toHaveLength(1)

// Alice adds a second device also called 'laptop'
const secondLaptop = createDevice({ userId: alice.userId, deviceName: 'laptop' })
alice.team.addForTesting(alice.user, [], redactDevice(secondLaptop))
expect(alice.team.members(alice.userId).devices).toHaveLength(2)

// Alice removes the first laptop
alice.team.removeDevice(alice.device.deviceId)

// The second laptop is still there
expect(alice.team.members(alice.userId).devices).toHaveLength(1)
})

it('deviceWasRemoved works as expected', () => {
const { alice, bob } = setup()
alice.team.removeDevice(bob.device.deviceId)
Expand Down
2 changes: 1 addition & 1 deletion packages/auth/src/team/transforms/removeDevice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const removeDevice =
member.userId === userId
? {
...member,
devices: member.devices?.filter(d => d.deviceName !== removedDevice.deviceName),
devices: member.devices?.filter(d => d.deviceId !== removedDevice.deviceId),
}
: member

Expand Down
2 changes: 1 addition & 1 deletion packages/auth/src/util/actionFingerprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const actionFingerprint = (link: TeamLink) => {
}

case 'ADD_DEVICE': {
return action.payload.device.deviceName
return action.payload.device.deviceId
}

case 'REMOVE_DEVICE': {
Expand Down

0 comments on commit 96fdca9

Please sign in to comment.