Back

[SOLVED] User Name

  • 0
  • Web
Kenny
28 Jun, 2023, 23:40

Is there any way to get a user name by providing an ID from the client? Or is this only avaliable via the server sdk?

TL;DR
Solution: To get a user name by providing an ID from the client, you can follow these steps: 1. Create a collection with `any.read` permission and add attributes for user_id and user_name. 2. Run a function to iterate over all existing users and add them to the new collection. 3. Set up a function triggered by the event `users.*.create` to add newly created users to the collection. This way, you can access user names by ID from the client side.
Binyamin
29 Jun, 2023, 00:46

Like searching for a user by ID? You can't do it in the client side out of the box.

But, a good workaround will be:

  1. <:databases:1108648029243838465> Create a collection, and give it permission of any.read and add these attributes
  • user_id
  • user_name
  1. For all existing users, you can run some function in your local machine that will iterate over all of them and will add them to the newly created collection.
  2. <:functions:1108648038156746792> From now on, you can create a function and set it to be triggered on the event users.*.create that will be fired any time a new user is created. Then, you can add the newly created user to the collection.
Kenny
29 Jun, 2023, 00:54

Thanks!!

Binyamin
29 Jun, 2023, 00:54

<a:agooglethumbsup:635256484682530825>

Meldiron
29 Jun, 2023, 07:44

I really like the approach above 😇 Apps usually call this "onboarding" process. In my apps I personally dont put userID into collection, instead, save ID of profiles document on user preferences. Clients usually dont care about user ID of a profile anyway, and it adds extra complexity if yoy want to store this user ID reliably.

Bouahaza
29 Jun, 2023, 10:47

Or create a function wich call GET.user via API keys based on params ?

Binyamin
29 Jun, 2023, 13:03

That's also a good idea. The logic behind keep it on the database aspect instead of function, its performance wise.

As if you can have the data in a public collection then each time you're requesting the information you going to do only one request. compere to function that you'll need to do two each request.

Kenny
30 Jun, 2023, 17:37

User Name [Solved]

Guille
30 Jun, 2023, 17:43

[SOLVED] User Name

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