‫So now let's attempt to access our data
‫from Supabase on our local computer,
‫and then we're gonna learn about row-level security.
‫So back here in Supabase, let's now come to this API docs.
‫So basically, Supabase automatically creates an entire
‫API documentation for all of our tables,
‫so that's really helpful, and so let's check it out
‫here for the cabins.
‫So essentially, we can access our data
‫using the JavaScript library, so by using this,
‫and then all we have to do is to copy this code,
‫or we can use it as an actual RESTful API.
‫So, that's what this here is.
‫So we can basically just send a request to this URL
‫right here, where this first part here
‫is the URL of our project, and then we have here our table
‫and then all the columns that we want.
‫Then we need to send our API key, and then here again,
‫that key has an authorization header.
‫So let's actually try to do that here.
‫And so for each of the table columns,
‫we have a different example here that we can copy,
‫but let's come to the one where we read all the rows.
‫So then let's come here, where it says that the project
‫API key is hidden, and so then here we need to select
‫that we actually want to show our public,
‫so this anon key right here.
‫And so then basically this here is the key
‫that we can use on the front end to access our data,
‫but more about that later.
‫For now, let's just copy this code
‫and paste it into some terminal,
‫because this is going to be a curl request.
‫So curl is basically to make some HTTP requests
‫right in the terminal.
‫So let's paste that in, then let's hit enter,
‫and we don't get an error, which is already a success.
‫Now, we also don't get any data, so instead,
‫we only get this empty array here, and so the reason
‫for that is the row-level security that we enabled
‫at the very beginning when we first created this table.
‫So what these row-level security tables do
‫is to prevent anyone who owns this key here
‫from basically doing whatever they want with our database.
‫So if it wasn't for the role level security
‫or RLS policies then whoever had this key here could really,
‫for example, delete our database
‫or edit whatever they wanted.
‫So of course, we don't want that to happen.
‫We only want certain operations to be allowed,
‫and so that's why we can cert, and so that's what we can set
‫these RLS policies for.
‫So, row-level security policies.
‫So let me show you how we can do that.
‫So let's come here to authentication.
‫Yeah, and then here is policies.
‫So let's click on policies, and then here,
‫we have our four tables.
‫And by the way, if you're wondering why we didn't create
‫that users table for authentication,
‫it's because we will do that separately.
‫So the Supabase authentication feature
‫doesn't require us to manually create a table,
‫but instead, Supabase will do that automatically.
‫Our users are then gonna be saved here in this table.
‫But for now, let's stay here
‫on these row-level security policies.
‫So we were working with the cabins table, and here again,
‫we can see that this role level security
‫is actually enabled, and so that is, again,
‫the reason why we didn't receive the data
‫when we did that request.
‫So in order to now allow us to actually receive the data,
‫let's create a new policy.
‫And so then let's select get started quickly,
‫'cause we just want to create a policy from a template,
‫and so actually this first one
‫is exactly what we want for now.
‫So first we want to enable everyone to have read access
‫to this table, while later, we will probably then enable
‫this one here, so only for authenticated users.
‫But now let's do this one, use this template, and then
‫we really just have to click here on review and save.
‫Okay. And so what this one will do, as the name says,
‫is to enable read access for everyone.
‫And so if we come back to our terminal
‫and then try that again, then...
‫Beautiful! We have now our array
‫with this very first object that we created.
‫So this first cabin. Great!
‫And if we wanted to create a post request,
‫so, to create a new cabin, then that again
‫would not be allowed, because we didn't create a new policy
‫for that type of access yet,
‫and we actually won't do that for now,
‫so for now, let's just enable access
‫to all of these resources for all users.
‫And later on we will then again change this so that only
‫locked in users, so only authenticated users, can do this.
‫So, can access all resources.
‫Okay...
‫And then also for the settings.
‫So this code here is not really important.
‫What matters is that now we will be able to access
‫all this data right in our React application,
‫and so let's actually do that in the next video.