Other users (not current) avatar

How do I access all user's information (like what we have with current_user) so that I can generate avatars of others based on their email, for example? The table component already does that when column type is User Email, but I want to do this with a standalone avatar component (for other users different than the current)

@igoraguiar
I was trying to do something similar but was told getting users from groups within retool is not yet possible but being worked on if I recall correctly. The only way you could achieve what you want is if you had all users in your own db and pull from there.

1 Like

thank you @ScottR

Hey @igoraguiar! @ScottR recalled correctly :slightly_smiling_face: If you were to host Retool on-premise, you could access the database that stores all your users and their group info, but this isn't possible on Cloud.

1 Like

thank you victoria

We've had the same issue, and ended up using a retool db, but we were very unhappy with the idea of having to keep the DB up to date with the user base. I've added two simple scripts to handle that.

Our DB has a table called user_settings. It's very simple, we keep track of users email, full name, avatar url and a couple of unrelated stuff. We have a DB query called employeeData that retrieves it on page load and transforms the data to camelCase (hence the script later will use those):

SELECT 
    email_address, 
    full_name,
    avatar_url
FROM user_settings;

I added two DB queries on top of that - UpdateUserData and SaveNewUserData. We run a script on success of employeeData query:

const currentUserData = employeeData.data[current_user.email];

if(!currentUserData) {
  SaveNewUserData.trigger();
  return;
}

if(!currentUserData.avatarUrl || !currentUserData.fullName
) {
  UpdateUserData.trigger();
}

As the names suggests, UpdateUserData updates records in the user_settings db. I use key value pairs like so:


On success of UpdateUserData, we trigger employeeData again to get the updated value as otherwise it wouldn't show unless someone went out and into the home page again. Employee data won't trigger a loop cause this time on success it'll find all the data it was looking for.

SaveNewUserData works similar, except we insert a new row in the DB and add email_address as well to the payload. It also needs to trigger employeeData on success.

And that's it. Now we have a self updating replica of retools users DB, allowing us to avoid the pain of someone clicking through this. Hope this helps someone else!

2 Likes

Thanks so much for sharing!