Skip to content

QueryClient support defaultOptions queryKey for set token to queryKey? #9303

Answered by 976520
vaynevayne asked this question in General
Discussion options

You must be logged in to vote

@vaynevayne
If I understood correctly, you’re including the token in the queryKey to prevent cached data from a previous user being shown after a user switch — basically to isolate or invalidate queries on user change. That makes sense. 😁

That said, adding the token to the queryKey (as in your example using a custom queryKeyHashFn) might lead to some subtle cache duplication issues, since the token gets hashed in and may not be obvious from the key structure. If you include the token in the queryKey, there's a risk that the auth token could get exposed externally through browser devtools, error reporting tools, etc.

queryKey is an identifier that defines "what data to fetch." But the toke…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@TkDodo
Comment options

@vaynevayne
Comment options

@976520
Comment options

Answer selected by vaynevayne
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants