I’ve encountered an unexpected behavior when using secureStorage.getItem() to retrieve stored data. Specifically, when I try to access a key that does not exist in secureStorage, instead of returning null or undefined, it throws an error.
In the code above, if the key “token” doesn’t exist in secureStorage, the getItem function throws an error. From my understanding of typical storage systems (like localStorage or sessionStorage), when a key is missing, the expected behavior is to return null or undefined, not throw an error.
I was wondering if this behavior is intended in the UXP secureStorage API. Is there a way to safely check if a key exists in secureStorage without relying on catching errors?
Any clarification or advice on how to handle this issue would be greatly appreciated!
Had to deal with exactly this a couple of days ago. According to docs it should throw an error only if the provided key is something other than string, but that’s not the case.
Most likely a bug, but I’m so tired of reporting them without any response most of the time Even if it will be a confirmed bug, just put it into try/catch and don’t hold your breath for it to be fixed any time soon
I don’t know what’s happening in decodeToken(storedToken);.
But why don’t You check, if storedToken is actually valid before passing it to decodeToken()?
Yeah, I suspected it might be a bug. Frustrating that these issues don’t get much attention. I’ll wrap it in a try/catch for now, thanks for confirming! Have you found any other quirks with secure storage?
Thank you @ismail3762@Karmalakas for bringing this issue to notice. I have created a UXP ticket. This should be a quick change and it will be fixed with next UXP release 8.2.