alls
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
export const USER_INFO_UPDATED_EVENT = 'user-info-updated';
|
||||
|
||||
function getCachedUserInfo() {
|
||||
try {
|
||||
const raw = window.localStorage.getItem('userInfo');
|
||||
return raw ? JSON.parse(raw) : {};
|
||||
} catch (error) {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
export function updateCachedUserInfo(changes) {
|
||||
if (typeof window === 'undefined' || !window.localStorage) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const nextUserInfo = {
|
||||
...getCachedUserInfo(),
|
||||
...(changes && typeof changes === 'object' ? changes : {})
|
||||
};
|
||||
|
||||
try {
|
||||
window.localStorage.setItem('userInfo', JSON.stringify(nextUserInfo));
|
||||
} catch (error) {
|
||||
void error;
|
||||
}
|
||||
|
||||
window.dispatchEvent(new CustomEvent(USER_INFO_UPDATED_EVENT, { detail: nextUserInfo }));
|
||||
return nextUserInfo;
|
||||
}
|
||||
Reference in New Issue
Block a user