Session storage shouldn't be undefined in newer browsers

Tried FF incognito
This commit is contained in:
Manav Rathi 2024-05-24 20:24:27 +05:30
parent 54820689c2
commit 11cc8e46b7
No known key found for this signature in database

View file

@ -3,31 +3,14 @@ export enum SESSION_KEYS {
KEY_ENCRYPTION_KEY = "keyEncryptionKey",
}
export const setKey = (key: SESSION_KEYS, value: object) => {
if (typeof sessionStorage === "undefined") {
return null;
}
export const setKey = (key: SESSION_KEYS, value: object) =>
sessionStorage.setItem(key, JSON.stringify(value));
};
export const getKey = (key: SESSION_KEYS) => {
if (typeof sessionStorage === "undefined") {
return null;
}
const value = sessionStorage.getItem(key);
return value && JSON.parse(value);
};
export const removeKey = (key: SESSION_KEYS) => {
if (typeof sessionStorage === "undefined") {
return null;
}
sessionStorage.removeItem(key);
};
export const removeKey = (key: SESSION_KEYS) => sessionStorage.removeItem(key);
export const clearKeys = () => {
if (typeof sessionStorage === "undefined") {
return null;
}
sessionStorage.clear();
};
export const clearKeys = () => sessionStorage.clear();