Back

How can I get a user’s name with their ID?

  • 0
  • Accounts
  • Web
ideclon
22 Aug, 2023, 15:20

I’m creating a comments system in an app - only signed in users can comment. I want to store each user’s ID with the comment (each comment is a document), then get the user’s name to display on the page.

TL;DR
The user wants to get a user's name with their ID in a comments system. The solution provided is to either use the Users SDK inside a cloud function or create two collections, one for comments and one for user details. Storing the user ID with the comment and updating the second collection when the user changes their name can be a solution. This allows accessing the user's name without using a cloud function.
Binyamin
22 Aug, 2023, 15:24

Either

  • Use the Users sdk inside a <:functions:1108648038156746792> cloud function
  • Store the ID with the username - can be problematic in case the username has changed, for that you can go with this 👇 approach

2 Collections

1st collection will be

  • comment
  • date
  • user_id

2nd collection will be the user details

  • user_id
  • user_name

So that's way you'll need to update only the 2nd collection when the user changes is name, and also you can make the second collection accessible without a having to use cloud function.

ideclon
22 Aug, 2023, 15:26

Seems a bit much - this is just an addon feature that’s not really required - it would just be a bit useful. I guess I’ll just store the name directly

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more