rafaelwendel / phpsupabase

PHP Client to use Supabase
MIT License
187 stars 18 forks source link

`404 Not Found` response: 404 page not found #6

Closed BnewVanZuarez closed 2 years ago

BnewVanZuarez commented 2 years ago

Thank you for building this library! When I try to use $db = $service->initializeDatabase('categories', 'id'); $newCategory = ['categoryname' => 'ibnuraffy@duck.com']; $data = $db->insert($newCategory);

I get the error Client error: 'POST https://MY_URL_PROJECT.supabase.co/auth/v1/categories' resulted in a '404 Not Found' response: 404 page not found

Do you have any suggestion what might cause this?

rafaelwendel commented 2 years ago

Hi BnewVanZuarez,

What base URL are you using? There are 2 different parameters. One for authentication (auth) and one for the database (rest). Look:

BnewVanZuarez commented 2 years ago

I See, I didn't read the documentation carefully, thank you

alexpi commented 1 year ago

I am also having a problem with this. If I understand correctly, the same Service instance must be used for auth and database manipulation, or else the bearer tokens don't match. How do we switch the base URLs for each use?

rafaelwendel commented 1 year ago

Hi Alexpi,

Generally you will have a page to do the authentication, and therefore you will create an instance of the service class using the auth endpoint. After authenticating, you will save the bearer token (in the session, for example) and then in the other pages you will create the instance of the service class according to your needs (generally, using the rest endpoint).

But anyway, I'll take your suggestion and add the setUrlBase method in future versions.

Thank you for your contribution

alexpi commented 1 year ago

Hi @rafaelwendel,

I did what you describe roughly, and I am getting a 'new row violates row-level security policy for table' 403 error. I guess this is related to the setup of Supabase rules, and not your library. It's the first time I am using Supabase and I have to study more!

Thanks

rafaelwendel commented 1 year ago

Hi Alexpi,

You're right. The RLS (Row Level Security) is controlled by Supabase itself, according to the rules that you create within your own project.

Read more at: https://subase.com/docs/guides/auth/row-level-security