Hi!
So I did a little more testing, and the example you provided definitely works. I also tested the case within my own app of using getItem
immediately after using setItem
and it works as well. So clearly the value is getting set, but while I’m in development mode it isn’t persisting across page reloads. Here is my toolbar as I’m developing my dashboard widget:
I remember reading something about how the storage instance is not shared across different apps. Is it possible there is some interaction of the development environment creating a new storage context every time it reloads?
Here is the code I’m using:
export function getUserRoleFromStorage(userId) {
return monday.storage.instance.getItem(getUserRoleKey(userId))
.then(res => _.get(res, 'data.value'));
}
export function setUserRole(userId, role) {
return monday.storage.instance.setItem(getUserRoleKey(userId), role);
}
export async function getCurrentUser() {
const currentUser = await getCurrentUserFromApi();
if (!currentUser.id) return {};
const role = await getUserRoleFromStorage(currentUser.id);
return { ...currentUser, role };
}
getCurrentUser gets run every time the app loads up, but always has role = null