Storage API not working?

I am trying to use the storage api to persist data across user sessions. I am using it as described in the documentation:
monday.storage.instance.setItem(‘USER_123456_ROLE’, ‘BASIC_ROLE’);
which returns a success message. However when I then use
monday.storage.instance.getItem(‘USER_123456_ROLE’);
it always returns value: null. How do I get this working?

Thanks,
Jake

Hey Jake! Can you share an example of the code you’re using to set and return the data? Are there any errors being thrown? You’re describing the correct usage of the API, so I’m guessing something else is going on.

By the way, here’s a super simple storage API example I cooked up recently for a product demo. It should give you an example of how to use it: Storage API Example

1 Like

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

Hello! Any update on this? I’m hoping this is a dev only thing, in which case I can build my app expecting the feature to work. But I haven’t had the chance to test it out in “production” yet.