Hey Moralis community
Just wanted to ask a question about your experiences in running Moralis powered web applications.
I’m working on an React / Next.js app and the user should be able to toggle between light and dark theme in frontend.
For saving a custom setting in Moralis (I want it stored in the users’ profile) I currently do it like this:
user.set("settings", { theme: "dark" })
await user.save()
and it works, a custom object settings
is stored with theme: "dark"
in it.
My case is now that if I use this data to set the users theme accordingly, the toggling between light and dark theme works great (also storing it accordingly in the User Object) BUT only in the current browser tab.
If I try out another browser, or a new tab in the same browser, where the same user is also logged in already, changing the value won’t affect the user data there, even after page reload.
It is a bit weird as I am not requesting the data from localStorage or so but from the Moralis database itself with user.attributes.settings.theme
to get the value.
Expected behaviour:
After toggling the settings and after page reload in other browsers the theme should be changed and console.log(user.attributes.settings.theme)
should return the updated value from the Moralis User Object.
what happens:
theme does not change on page reload in other browsers and also console.log(user.attributes.settings.theme)
still consoles the same value, even though the value was changed in the database with user.set() and saved with user.save() in another tab / browser.
BUT IT WORKS great after logout and login by the way! The value shows correctly after logout / login in other browsers.
Now I’m trying to figure out if this happens because of my react/app configuration or if there is some caching built into Moralis, or maybe someone else has the same issue … how to solve this problem?
Hopefully it is clear what I want to achieve.
Thanks and best regards! Tim