What to call in RSC to validate that the user is logged in?
I want to check in my RSC that the user is logged in. In Client Components we have the components and hooks from convex/react but these components are using hooks so they should not work on RSCs.
11 Replies
I want to validate if the user is logged in on the server and based on this render a client component, which makes authenticated requests to the convex backend (if logged in) or a server component (if logged out)
You can either rely on your auth provider or fetchQuery a custom query that gives you the auth status for given token.
So for clerk, can I do this??

Because don't we land again in that problem when only using the clerk check and not the convex check? https://discord.com/channels/1019350475847499849/1225252977699455067
When the client component renders the client will not be authenticated yet.
So for the client components you still need to use the same approach (like wrapping in Authenticated), if youβre using useQuery in them.
but then the server component clerk check is not needed anymore, if you rely anyways on the convex check? wouldn't it be good if you can directly check everything in the server component check
then there is no need to double check
but the problem remains. I first check via convex in the root server component this is true so I render the client component and this gives me false so I have a problem
that these two checks (server and client) are not in sync, because they are testing different things (clerk only clerk and convex also this convex auth token thing)
In
https://github.com/nutlope/notesgpt
you can see that we avoid this issue by simply return
null
from queries when they are not authenticated. This way you don't need to use Authenticated
or useConvexAuth
in your client components.GitHub
GitHub - Nutlope/notesGPT: Record voice notes & transcribe, summari...
Record voice notes & transcribe, summarize, and get tasks - Nutlope/notesGPT
ok, that does make way more sense than throwing an error ig. I just followed this example on the functions-auth documenation page

I will try this one out