BaBa
BaBa
TTCTheo's Typesafe Cult
Created by BaBa on 10/25/2023 in #questions
useQuery enabled depending on login state
Hi, I need to prevent useQuery from executing when the user isn't logged in. However, this requires me to include {enabled: isLoggedIn} in nearly all of my queries. I'm considering doing something like this:
const useAuthenticatedQuery = (options) => {
const { data: isLoggedIn } = useIsLoggedIn();
return useQuery({
...options,
enabled: isLoggedIn && (options.enabled ?? true)
});
};
const useAuthenticatedQuery = (options) => {
const { data: isLoggedIn } = useIsLoggedIn();
return useQuery({
...options,
enabled: isLoggedIn && (options.enabled ?? true)
});
};
Because this could potentially result in significant alterations to my codebase, I would like to seek your input before proceeding with it. Thank you ❤️
8 replies