MCPcopy Create free account
hub / github.com/flatlogic/react-material-admin / syncUserInLocalStorage

Function syncUserInLocalStorage

src/context/ManagementContext.js:45–73  ·  view source on GitHub ↗
(updatedUser)

Source from the content-addressed store, hash-verified

43}
44
45function syncUserInLocalStorage(updatedUser) {
46 const rawUser = localStorage.getItem('user');
47
48 if (!rawUser || !updatedUser?.id) {
49 return;
50 }
51
52 try {
53 const parsedUser = JSON.parse(rawUser);
54 const currentUserId = parsedUser?.user?.id;
55
56 if (!currentUserId || String(currentUserId) !== String(updatedUser.id)) {
57 return;
58 }
59
60 localStorage.setItem(
61 'user',
62 JSON.stringify({
63 ...parsedUser,
64 user: {
65 ...parsedUser.user,
66 ...updatedUser,
67 },
68 }),
69 );
70 } catch {
71 return;
72 }
73}
74
75let ManagementStateContext = React.createContext();
76let ManagementDispatchContext = React.createContext();

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected