Best place to keep fetched data from external APIs

Hi, I have the data fetched after authenticating the user, what is the best place to store that data?

Currently i am storing that in


1 Like

Hi again, @aeyzazkhan :wave:

Ok, well, the Frontity state is intented to store that state of your application that it’s shared between packages and connected to your React components so they render again when your state changes.

As the data included in state is exposed to other packages, a third-party package could read the secureData object, making it insecure. You could include it in libraries in such a way other packages can use your authentication library without accessing the secure data, although I think it’s better that you don’t expose it in at all in the package (neither state nor libraries), and use code that can only be accessed by that part of your application responsible for authentication.

Not storing things in state because any package can read it would be like not storing things in the WP settings (MySQL) because any other plugin can read it. It doesn’t make much sense. Just make sure you trust the Frontity packages you install, the same way you trust the WP plugins you install.

Regarding state.user, my only concern would be that the user namespace could be used in the future by a Frontity Auth package. If you would use both, they will conflict. Other than that, it’s perfectly fine. You can read more about why we use namespaces here:

By the way, just a quick note here: libraries is not reactive: changes to stuff inside libraries won’t make your React component re-render when necessary. That only happens in state.

I didn’t see it that way but you are absolutely right! :sweat_smile:

@aeyzazkhan, do it as @luisherranz said, it’s the best way.