Skip to content
Discussion options

You must be logged in to vote

Hm. I would argue that loginUser itself should be a mutation: https://twitter.com/TkDodo/status/1483157923572457476

While your dependent query might work, there is no guarantee that you get a new token after one hour. For example, if you have a successful token and the hour passes, the token query becomes stale. If you then mount useData, useToken will trigger a background refetch, but it will stay in success state and your data query will be immediately enabled, running with the outdated token.

Usually, a better approach is to:

  • have login be a mutation
  • take the response token and put it somewhere (localStorage, zustand, redux)
  • in each queryFn / mutationFn, read the global token and send it

Replies: 1 comment 3 replies

Comment options

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

@mfpopa
Comment options

@raegen
Comment options

Answer selected by icaroponce
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants