index.ts 830 B

123456789101112131415161718192021222324252627282930313233
  1. export enum SESSION_KEYS {
  2. ENCRYPTION_KEY = "encryptionKey",
  3. KEY_ENCRYPTION_KEY = "keyEncryptionKey",
  4. }
  5. export const setKey = (key: SESSION_KEYS, value: object) => {
  6. if (typeof sessionStorage === "undefined") {
  7. return null;
  8. }
  9. sessionStorage.setItem(key, JSON.stringify(value));
  10. };
  11. export const getKey = (key: SESSION_KEYS) => {
  12. if (typeof sessionStorage === "undefined") {
  13. return null;
  14. }
  15. const value = sessionStorage.getItem(key);
  16. return value && JSON.parse(value);
  17. };
  18. export const removeKey = (key: SESSION_KEYS) => {
  19. if (typeof sessionStorage === "undefined") {
  20. return null;
  21. }
  22. sessionStorage.removeItem(key);
  23. };
  24. export const clearKeys = () => {
  25. if (typeof sessionStorage === "undefined") {
  26. return null;
  27. }
  28. sessionStorage.clear();
  29. };