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 @@ -40,3 +40,6 @@ VITE_SERVICE_EXPIRED_TOKEN_CODES=9999,9998
4040
4141# when the route mode is static, the defined super role
4242VITE_STATIC_SUPER_ROLE = R_SUPER
43+
44+ # Used to differentiate storage across different domains
45+ VITE_STORAGE_PREFIX = SOY_
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import localforage from 'localforage';
33/** The storage type */
44export type StorageType = 'local' | 'session' ;
55
6- export function createStorage < T extends object > ( type : StorageType ) {
6+ export function createStorage < T extends object > ( type : StorageType , storagePrefix : string ) {
77 const stg = type === 'session' ? window . sessionStorage : window . localStorage ;
88
99 const storage = {
@@ -16,15 +16,15 @@ export function createStorage<T extends object>(type: StorageType) {
1616 set < K extends keyof T > ( key : K , value : T [ K ] ) {
1717 const json = JSON . stringify ( value ) ;
1818
19- stg . setItem ( key as string , json ) ;
19+ stg . setItem ( ` ${ storagePrefix } ${ key as string } ` , json ) ;
2020 } ,
2121 /**
2222 * Get session
2323 *
2424 * @param key Session key
2525 */
2626 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 } ` ) ;
2828 if ( json ) {
2929 let storageData : T [ K ] | null = null ;
3030
@@ -37,12 +37,12 @@ export function createStorage<T extends object>(type: StorageType) {
3737 }
3838 }
3939
40- stg . removeItem ( key as string ) ;
40+ stg . removeItem ( ` ${ storagePrefix } ${ key as string } ` ) ;
4141
4242 return null ;
4343 } ,
4444 remove ( key : keyof T ) {
45- stg . removeItem ( key as string ) ;
45+ stg . removeItem ( ` ${ storagePrefix } ${ key as string } ` ) ;
4646 } ,
4747 clear ( ) {
4848 stg . clear ( ) ;
Original file line number Diff line number Diff line change @@ -101,5 +101,7 @@ declare namespace Env {
101101 * @link https://docs.iconify.design/api/providers.html
102102 */
103103 readonly VITE_ICONIFY_URL ?: string ;
104+ /** Used to differentiate storage across different domains */
105+ readonly VITE_STORAGE_PREFIX ?: string ;
104106 }
105107}
Original file line number Diff line number Diff line change 11import { createLocalforage , createStorage } from '@sa/utils' ;
22
3- export const localStg = createStorage < StorageType . Local > ( 'local' ) ;
3+ const storagePrefix = import . meta . env . VITE_STORAGE_PREFIX || '' ;
44
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 ) ;
68
79export const localforage = createLocalforage < StorageType . Local > ( 'local' ) ;
You can’t perform that action at this time.
0 commit comments