ForkMeDaddy
ForkMeDaddyโ€ข12mo ago

Identity is null during CSR

I am preloading a query during SSR however when a client component calles usePreloadedQuery the same code block has the identity as null and therefore throws an error. Any ideas what the problem could be?
No description
2 Replies
ForkMeDaddy
ForkMeDaddyOPโ€ข12mo ago
actually the SSR part doesnt matter. same result while calling useQuery directly the route accessed is a non-public route (done with clerk) so I assume when I am on the page the user should be available but what I see is when useing useConvexAuth "isAuthenticated" is first false then true. Do I really have to check this beforehand? In fact how can it be that the Identity is known during SSR but then unknown for a short amount of time during client side rendering. This seems like not a very good behaviour wouldn't this behaviour defeat the point from SSR rendering? Because when I load the page on the server authenticated queries run (according to the docs, passing the auth token) but when the client hydrates state it would show something different because authenticated queries cannot be run and need to be delayed. Wouldn't this lead to hydration errors Or am I not geting it correctly? ๐Ÿ˜„
Michal Srb
Michal Srbโ€ข12mo ago
Hey, please follow this repo for an example of SSR with auth: https://github.com/Nutlope/notesGPT/blob/main/lib/hooks.tsx The approach is: - Return null from queries when they are not authenticated - On the client ignore the null result, returning the preloaded data until the result becomes not-null
GitHub
notesGPT/lib/hooks.tsx at main ยท Nutlope/notesGPT
Record voice notes & transcribe, summarize, and get tasks - Nutlope/notesGPT

Did you find this page helpful?