Authorization still triggering fetch when using conditional routing for AuthProvider

Hi guys and girls, I'm currently running into an issue where I have some basic routing in an auth provider. On mount it checks if there is a user / session. If no session or user is present, I redirect to the /login page. This all works. The minute I am not logged in, but visit / or /bookings it still runs any createResource present on that page. In my use case I'm actually using createCachedResource which is @lxsmnsyc library. In my case the cache is storing the empty results when I login again. Was wondering how you'd go about preventing anything from fetching until the auth is resolved. What I see happening is, when you visit /bookings and you're not logged in, it runs that route figures out if you're logged in or not, then redirects to login. But at that point the fetcher has already started.
2 Replies
lxsmnsyc
lxsmnsyc2y ago
You should refresh the cache on route change I guess OR you can move the CacheBoundary to a lower level rather than outside the routes. Maybe on a per-page basis? Something like <Route path="/" component={() => <CacheBoundary><MyPage /></CacheBoundary>} />
Casacobra
Casacobra2y ago
@lxsmnsyc thanks for your reply! One thing I've noticed and I'm not too sure why but the refresh cache doesn't work at all in my use case
Want results from more Discord servers?
Add your server