martinkasa / capacitor-secure-storage-plugin

Capacitor plugin for storing string values securly on iOS and Android.
MIT License
152 stars 53 forks source link

keys() returns key names with "cap_sec_" prefix on web platform #43

Closed mrosinski closed 2 years ago

mrosinski commented 2 years ago

Consider below code:

await SecureStoragePlugin.set({ key: 'key', value: 'value' })

const { value: keys } = await SecureStoragePlugin.keys()
// [ 'cap_sec_key' ]

await SecureStoragePlugin.get({ key: keys[0] })
// 'Item with given key does not exist'

It fails, because .keys() function returns keys with cap_sec_ prefix and .get() function adds the prefix again, so it looks for cap_sec_cap_sec_key instead of cap_sec_key.

This affects web platform only. The above code works fine on Android and iOS platforms.