how to use getUserIdentity with fetchQuery (server component)
getUserIdentity returns null when working this way
7 Replies
Have you followed
https://docs.convex.dev/client/react/nextjs/server-rendering#server-side-authentication
?
Next.js Server Rendering | Convex Developer Hub
Next.js automatically renders both Client and Server Components on the server
my bad, but thanks!
Hi @Michal Srb , I'm using this repo: https://github1s.com/xixixao/convex-auth/tree/convex-auth-lib to implement auth. I use fetchQuery to get user data from a server component always return null. The link you've provided above required an access token to validate, but how to get that from this repo or to create a new one. Thanks
@hugo the token has to come from you auth provider.
When you are using
useQuery
convex automatically grabs it from the client, so you don't have to manually pass your token.
With fetchQuery
you have to manually pass the token prop. You can get this from your auth provider, in my case that's Clerk:
I re-use that function any time I need to fetch. You could also create a function that wraps fetchQuery
for fetchAuthQuery
that injects the tokenHey @hugo, that code is old. The library I'm working on is still WIP. To your question, the library will have a separate Next.js integration.
thank you
@hugo The Next.js integration is not out yet but the library is, see https://docs.convex.dev/auth/convex-auth
Convex Auth | Convex Developer Hub
Convex Auth is a library for implementing authentication directly within your