File tree Expand file tree Collapse file tree 4 files changed +14
-7
lines changed Expand file tree Collapse file tree 4 files changed +14
-7
lines changed Original file line number Diff line number Diff line change @@ -43,3 +43,6 @@ VITE_STATIC_SUPER_ROLE=R_SUPER
43
43
44
44
# sourcemap
45
45
VITE_SOURCE_MAP = N
46
+
47
+ # Used to differentiate storage across different domains
48
+ VITE_STORAGE_PREFIX = SOY_
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import localforage from 'localforage';
3
3
/** The storage type */
4
4
export type StorageType = 'local' | 'session' ;
5
5
6
- export function createStorage < T extends object > ( type : StorageType ) {
6
+ export function createStorage < T extends object > ( type : StorageType , storagePrefix : string ) {
7
7
const stg = type === 'session' ? window . sessionStorage : window . localStorage ;
8
8
9
9
const storage = {
@@ -16,15 +16,15 @@ export function createStorage<T extends object>(type: StorageType) {
16
16
set < K extends keyof T > ( key : K , value : T [ K ] ) {
17
17
const json = JSON . stringify ( value ) ;
18
18
19
- stg . setItem ( key as string , json ) ;
19
+ stg . setItem ( ` ${ storagePrefix } ${ key as string } ` , json ) ;
20
20
} ,
21
21
/**
22
22
* Get session
23
23
*
24
24
* @param key Session key
25
25
*/
26
26
get < K extends keyof T > ( key : K ) : T [ K ] | null {
27
- const json = stg . getItem ( key as string ) ;
27
+ const json = stg . getItem ( ` ${ storagePrefix } ${ key as string } ` ) ;
28
28
if ( json ) {
29
29
let storageData : T [ K ] | null = null ;
30
30
@@ -37,12 +37,12 @@ export function createStorage<T extends object>(type: StorageType) {
37
37
}
38
38
}
39
39
40
- stg . removeItem ( key as string ) ;
40
+ stg . removeItem ( ` ${ storagePrefix } ${ key as string } ` ) ;
41
41
42
42
return null ;
43
43
} ,
44
44
remove ( key : keyof T ) {
45
- stg . removeItem ( key as string ) ;
45
+ stg . removeItem ( ` ${ storagePrefix } ${ key as string } ` ) ;
46
46
} ,
47
47
clear ( ) {
48
48
stg . clear ( ) ;
Original file line number Diff line number Diff line change @@ -101,5 +101,7 @@ declare namespace Env {
101
101
* @link https://docs.iconify.design/api/providers.html
102
102
*/
103
103
readonly VITE_ICONIFY_URL ?: string ;
104
+ /** Used to differentiate storage across different domains */
105
+ readonly VITE_STORAGE_PREFIX ?: string ;
104
106
}
105
107
}
Original file line number Diff line number Diff line change 1
1
import { createLocalforage , createStorage } from '@sa/utils' ;
2
2
3
- export const localStg = createStorage < StorageType . Local > ( 'local' ) ;
3
+ const storagePrefix = import . meta . env . VITE_STORAGE_PREFIX || '' ;
4
4
5
- export const sessionStg = createStorage < StorageType . Session > ( 'session' ) ;
5
+ export const localStg = createStorage < StorageType . Local > ( 'local' , storagePrefix ) ;
6
+
7
+ export const sessionStg = createStorage < StorageType . Session > ( 'session' , storagePrefix ) ;
6
8
7
9
export const localforage = createLocalforage < StorageType . Local > ( 'local' ) ;
You can’t perform that action at this time.
0 commit comments