Display user specific information from supabase table in the form input field

Hello,

i feel like im missing something here, since this seems like it should be an easy task. I have a form with an information unique to every user. Once that the user filled out this form (updated his row in Supabase table) is it possible to show these informations as a place holder (or initial value)?

Here is an example:

Should i use some lookup formula and look up the UUID or what would be the right approach?
Any advice will be appreciated:)

Assuming your user is logged in, you can bind the init value of your input to a field in the current user variable:

Depending on your use case, you may want to use a different approach with a profile table in the public schema of your Supabase project that is synced to the users table in the auth schema.

It’s a more advanced technique which you can learn about here.

So either way the right approach would be to save all these informations as users metadata - either in a private users table or synced profile table - and then just link to the metadata right?

Mmm not sure there’s a right way. The wrong way would be to have personal data in a table in the public schema with no RLS (or poorly configured RLS) but otherwise, there are different approaches that would work.

For example, if you don’t need any user to be able to access other user’s information (think an HR admin who might need to be able to see an employee’s info), then you probably don’t need a profiles table at all. You could simply store everything in the metadata of the user.

If a big part of your app will be around user data, it might become impractical to store everything in the user metadata field of the users table. You could keep that field to a minimum and store most of the data in a well thought-out profiles table with one column per piece of information (instead of in one big json in the user metadata field of the users table).

Does that make sense?

Hello there,

first of all thank you for your response, i appreciate it!
And it does make sense for sure:) but lets say i did not want to use users metadata to store this information (since this is quite long and optional after sign-up form). If i have just a normal public table with proper RLS and users ID as a row primary key - what formula could i use in the front end to only display data for the specific logged in user?


For example in this screenshot right here the input will be always displaying “first_name” from “data[0]” for every user - is there a formula how to display “first_name” of logged in user (when im using user ID as primary key for the tables row)?

Hope this makes any sense.
Thank you for your patience:)

Oh, well you should not filter this information in the frontend! You should make sure the backend only returns the data from the current user.

In Supabase, you would add an RLS policy on your profiles table in the public schema so that a SELECT call only returns the info from the current user. It would look something like this:

When you use frontend filters, all the data is still loaded and visible in the user’s browser, even if it is not displayed on the page.

Frontend vs backend filters are super important concepts to understand to build a secure web-app. Here’s a video we made on the topic:

1 Like

Now i have finally got it right:)

Thank you so much for taking time to explain this!

1 Like

Of course! My pleasure :slight_smile: