Get username from a Clerk user

I'm building a blog and I want to display the author's username at the of each blog but I don't know how to get it other than with useUser() hook or currentUser(), but the problem with these 2 solutions is that it displays the current user username. Any help would be much appreciated and sorry for my english
15 Replies
carnegiepilled
carnegiepilled12mo ago
@Cxstum user.firstName on the User object
Cxstum
Cxstum12mo ago
It keeps telling me that it's undefined, do you think I should start using trpc to with my project to see if I can fix it because im only using mongodb and prisma. Thx for the help btw
carnegiepilled
carnegiepilled12mo ago
can you show code? no trpc is complex if you don't know that you need it, don't add it – you will waste days and it's not useful for the users
Cxstum
Cxstum12mo ago
@eula1
No description
Joseph_Ebuka
Joseph_Ebuka12mo ago
You should should maybe try a conditional check {user?.firstname}
carnegiepilled
carnegiepilled12mo ago
and where is the user coming from?
Cxstum
Cxstum12mo ago
What do you mean
carnegiepilled
carnegiepilled12mo ago
show the parent component where you do auth()
Cxstum
Cxstum12mo ago
@eula1 The problem now is that I don't know what to put in the user property
No description
NotLuksus
NotLuksus12mo ago
You need to save the users in your own db / make a look up at with the author id you have for your post The way you have it right now it would always be the signed in user not the actual author of the post So what you need todo is sync your clerk users to your db, or save a clerkUserId on the post entity in your database
NotLuksus
NotLuksus12mo ago
Actually now that I check the docs you probably need to sync users to your own db, check out this docs page: https://clerk.com/docs/users/sync-data#sync-data-to-your-backend-with-webhooks
Sync Clerk data to your backend with webhooks | Clerk
The recommended way to sync data between Clerk and your application's backend is via webhooks. In this guide you'll learn how to enable webhooks and how to set up your backend so that it is updated every time an event happens on your Clerk instance.
Cxstum
Cxstum12mo ago
Im pretty sure I did every step right so now what do I do to get the user information in my code. Btw im using prisma with mongodb
NotLuksus
NotLuksus12mo ago
I haven't used mongodb / no sql for a long time, but in theory what you can do is whenever you create a new post, associate that post with the user in your database The best way todo this imo is to have the user id = the clerk user id And then when you fetch the posts, just also fetch the authors information from the associated user
Cxstum
Cxstum12mo ago
What are you using right now?
NotLuksus
NotLuksus12mo ago
drizzle and postgres / mysql
Want results from more Discord servers?
Add your server