Complex encryption requirements and various issues we've encountered #8822
Unanswered
gregordotjs
asked this question in
Q&A
Replies: 1 comment
-
I think you might want to look into https://tanstack.com/query/latest/docs/framework/react/plugins/createPersister |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm working with Expo + tanstack query + async persister.
What's important to understand for my case is, that we have some api calls that return data that can be stored in async storage normally, and data that is really sensitive, and needs to be encrypted. So we added a meta with
encrypted
flag, and create our own serializer / deserializer.The first issue we encountered was, that
serialize
is getting called for all queries, not just the one that was added / executed. So we noticed that we kept encrypting same queries over and over again, even when none of those were executed. The workaround was to create some kind of a cache to store encrypted data there (example is below), so that we don't constantly call encrypt.The next issue was that we have some auth stuff tied to tanstack query (e.g., token verification). And because this is tied to tanstack query, and we use async persister,
deserialize
is getting called again for all queries. So what happens is, we deserialize and DECRYPT data that should be protected, even before the user logs in. Because tanstack query is needed for auth. I have no idea how to go around this.So basically my question is: should I even try to solve this with
serialize
/deserialize
or would some other approach be more suited, like encrypting data in api request queryFn, and decrypt it on success?Here's the code related to this issue:
Beta Was this translation helpful? Give feedback.
All reactions