Skip to content
Open
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
5 changes: 5 additions & 0 deletions .changeset/siwx-local-storage-delete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@reown/appkit-siwx': patch
---

Fix local storage session deletion to preserve sessions that do not match both the chain ID and account address.
2 changes: 1 addition & 1 deletion packages/siwx/src/storages/LocalStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class LocalStorage implements SIWXStorage {

delete(chainId: string, address: string): Promise<void> {
const sessions = this.getSessions().filter(
session => session.data.chainId !== chainId && session.data.accountAddress !== address
session => session.data.chainId !== chainId || session.data.accountAddress !== address
)
this.setSessions(sessions)

Expand Down
34 changes: 27 additions & 7 deletions packages/siwx/tests/storages/LocalStorage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,38 @@ describe('LocalStorage', () => {
expect(setItem).toHaveBeenCalledWith(key, JSON.stringify([session]))
})

test('should remove sessions', async () => {
test('should remove only sessions matching the chain and address', async () => {
const matchingSession = mockSession({
data: { accountAddress: '0xAAA', chainId: 'eip155:1' }
})
const duplicateMatchingSession = mockSession({
data: { accountAddress: '0xAAA', chainId: 'eip155:1' }
})
const sameChainSession = mockSession({
data: { accountAddress: '0xBBB', chainId: 'eip155:1' }
})
const sameAddressSession = mockSession({
data: { accountAddress: '0xAAA', chainId: 'eip155:137' }
})
const unrelatedSession = mockSession({
data: { accountAddress: '0xBBB', chainId: 'eip155:137' }
})

getItem.mockImplementation(() =>
JSON.stringify([
mockSession({
data: { accountAddress: '0x1234567890abcdef', chainId: 'eip155:1' }
})
matchingSession,
duplicateMatchingSession,
sameChainSession,
sameAddressSession,
unrelatedSession
])
)
expect(await storage.get('eip155:1', '0x1234567890abcdef')).toHaveLength(1)

await storage.delete('eip155:1', '0x1234567890abcdef')
await storage.delete('eip155:1', '0xAAA')
expect(getItem).toHaveBeenCalledWith(key)
expect(setItem).toHaveBeenCalledWith(key, JSON.stringify([]))
expect(setItem).toHaveBeenCalledWith(
key,
JSON.stringify([sameChainSession, sameAddressSession, unrelatedSession])
)
})
})
Loading