NazCodelandN
Convex Community9mo ago
14 replies
NazCodeland

Queries Invalidated on Auth Token Refresh (Clerk)

Hey, I’m running into a problem with Convex query invalidation.

Whenever my auth token is refreshed (I’m using Clerk, which refreshes every ~50 seconds as described: https://clerk.com/docs/how-clerk-works/overview#token-refresh-mechanism, Convex seems to invalidate and re-run queries that depend on authentication and also a query that doesn't depend on authentication—even when no data has changed and no mutations have occurred.

- My queries use
ctx.auth

- I’m calling
client.setAuth(fetchToken, handleAuthChange)
in my Svelte app.

All query invalidations are showing (cached) in the dashboard logs. However, from what I understand, even cached queries have a cost, although less than none-cached queries. However, I would like to avoid this altogether if possible since all these additional function calls will incur a cost and lead to additional bandwidth costs.

I'm 100% sure this is being caused by
client.setAuth(fetchToken, handleAuthChange);
because when I comment this line out (after it has been set once) and save. The queries are no longer getting invalidated.

I’ve gone through this GitHub issue: https://github.com/get-convex/convex-backend/issues/95 and this Discord thread Caching system failure., where auth token causing query invalidation was mentioned but in the rest of the conversation it didn’t really come up again.
Was this page helpful?