Replies: 1 comment 2 replies
-
I usually have an API endpoint returning the current logged in user (based on a cookie or header), then I create a query to fetch that endpoint and get the user, if there is no user I redirect to login, if there is user I continue. Another option, is that you can keep your auth outside RQ and use context to store the logged in user, then read from that place. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Sorry guys to bother you again :-/ I enrolled in React Query - Essentials. Was really a great help to get familiar with react-query. I'm currently trying to move all of my redux stuff I used in the past over to react-query. So far so good. I basically got rid of 99% of redux. Really awesome. Thanks a lot for that great library. I just have one best practice question on how to handle auth states. What I did in the past is after a user logged in successfully is stored in my user redux state eg
isAuthenticated
. Or I checked when my app is loaded if there is a token in my local storage, used that token to call an api endpoint -> on success I setisAuthenticated
. And based on that I was eg doing my routing like this:I wonder if eg for that example I should just use something like
const userQuery = useQuery('users', getUser);
And based on if that query is a success or if it returned me a user object, do my redirects? Or am I thinking in the wrong direction here?
Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions