How to get user details in server component
How can I get user details with convex auth on nextjs server component?
I have a query that works when used in client side with useQuery but it doesn't work with fetchQuery
7 Replies
^ works with client component/page
doesn't work with server component/page (getting null/undefined)
got it working with;
1) Get token in server session and pass to fetchQuery
2) Parse token and get userId
3) Use userId
I wonder if this is a bad practice?
this is how fetchQuery looks like
^ works nicely on production as well 🔥
ehhhh signout is not working
I don't know if this will impact you or not, but looks like an update is out: https://discord.com/channels/1019350475847499849/1019350478817079338/1273479617788903518
I did update/no changes
seems like this is happening to multiple users
https://discord.com/channels/1019350475847499849/1273008614000427099
@Oren for your original question the code is
Notice the extra second param.
see https://labs.convex.dev/auth/authz/nextjs#preloading-and-loading-data
Server-side authentication in Next.js - Convex Auth
Authentication library for your Convex backend
that is amazing. You kept me with convex tbh. I will upgrade and move from supabase 👍
Hey, i'm using clerk for auth, what would it look like for me?
Just going on docs, it looks like you want this: https://clerk.com/docs/references/nextjs/auth#use-auth-to-retrieve-user-id
That object it returns with userId is an auth object, it also has a
getToken()
method: https://clerk.com/docs/references/nextjs/auth-object#auth-object-properties