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.

Hi @jakedluhy,

Did you ever resolve this issue? I’m experiencing a similar problem. Interesting that you get the failure with such a simple, short data string. Simple strings work OK for me, then when I try it with my actual data I get the value: null result, like you.

I described my issue here - Editing files in an app - #5 by CMcConnell

Ya for me I was able to get it working once I uploaded a build and used that. It just doesn’t work in the sandbox/test environment (using ngrok).

Hi @jakedluhy,

Thanks for getting back to me. That’s interesting. I just updated my other post with an update. Turns out my problem stemmed from newline characters in the data I was attempting to write.

But that was testing an uploaded build, so it’s quite possible I might also see your issue too with ngrok, which would be doubly confusing, so it’s good to be know about.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.