Row level security and data insert with react native

Hi there,

I have a react native app and have auth setup, so that a session is created when a user logs in with their phone number.

I have row level security setup with the rule to allow users to do anything to their own lists.

But when testing if I try to create a list I'm getting this error:

error:  {"code": "42501", "details": null, "hint": null, "message": "new row violates row-level security policy for table \"lists\""}


This isn't making much sense to me because there is definitely a session for the user and I'm even passing in the user.id from the session into the user_id field in the table.

  const handleCreateList = async () => {
    try {
      setIsLoading(true);
      const { data, error } = await supabase
        .from("lists")
        .insert([
          {
            user_id: user.id,
            name: listName,
            google_place_id: selectedPlace.placeId,
            google_place_name: selectedPlace.description,
            google_place_types: JSON.stringify(selectedPlace.types),
          },
        ])
        .select();

      if (error) {
        throw error;
      }

      console.log(data[0].id);

      navigation.navigate("ListOverview", { listId: data[0].id });
    } catch (error) {
      console.log("error: ", error);
    } finally {
      setIsLoading(false);
    }
  };


Any ideas what the issue could be?

I run into a similar row level security issue when trying to read data using select with a logged in user.
Screen_Shot_2022-09-17_at_2.25.28_AM.png
Was this page helpful?