Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auth: using deviceId instead of deviceName to identify a device #127

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading