I'm working on a project that uses Supabase as the backend, and I've set up a public.profiles table to store user profile information. The table structure looks like this:
create table
public.profiles (
id uuid not null,
first_name text null,
last_name text null,
constraint profiles_pkey primary key (id),
constraint profiles_id_fkey foreign key (id) references auth.users (id) on delete cascade
) tablespace pg_default;
I want to be able to update the first_name
and last_name
columns in this table when a user updates their profile information. To do this, I've created the following functions in my application using Supabase:
// Function to update profile information
export async function addData(firstName, lastName) {
try {
const { data, error } = await supabase
.from('profiles')
.update({ first_name: firstName, last_name: lastName }) // Problematic line
.eq('id', userID);
if (error) {
throw error;
}
// Return some success data if needed
return { success: true };
} catch (error) {
return { error: error.message };
}
}
However, when I call this function to update the first_name and last_name columns, it doesn't seem to work as expected. The data doesn't get updated, and I'm not sure why.
- I've checked the Supabase table structure, and both
first_name
andlast_name
columns are defined as null, so they should allow updates. - I've ensured that I'm passing the correct userID to the eq condition when updating the record.
- I've checked that firstName and lastName are not null being passed into addData().
- I've checked that users can view, add, and update their own profile. (I can sucessfully view my profile, so I once again am sure that I have a session, and can view my profiles row, which is the same rule for updating)