You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As a modern developer, you know the sense of control when you can launch with a one-click. The prerequisite is to keep everything within the database. It's not just about convenience; it's about maintaining a single source of truth, ensuring consistency, and streamlining your workflow.
192
192
193
193
However, for RLS, you have to define authorization directly in the database, not in your source code. Of course, you could store it as an SQL file in your codebase, but you need to rely on SQL migration to ensure consistency. I think it’s the same reason why you seldom see people using stored procedures of databases nowadays despite all the benefits they offer.
194
194
195
-
What makes the consistency even worse is that, according to the official documentation of Supabase, you have to duplicate the policy filter in your application code for performance reasons:
195
+
What makes the consistency even worse is that you have to duplicate the policy filters in the application code. For example, if you are using the Supabase JS SDK, you have to use the two queries below to get the result:
Why? Because otherwise, you might experience 20x slower query performance, according to the official benchmark of Supabase. 😲
196
209
197
210
[Add filters to every query | Supabase Docs](https://supabase.com/docs/guides/database/postgres/row-level-security#add-filters-to-every-query)
198
211
@@ -318,38 +331,26 @@ What about the problems of RLS? Let’s go through them one by one.
318
331
319
332
The access policies are now defined alongside the database models. The schema becomes the single source of truth of your backend, enabling an easier understanding of the system as a whole.
320
333
321
-
Moreover, whether calling from the frontend or backend, you don’t need to use any filter regarding the authorization rules, which will be injected into queries automatically by the ZenStack runtime.
334
+
Moreover, whether calling from the frontend or backend, you don’t need to use any filter regarding the authorization rules, which will be injected into queries automatically by the ZenStack runtime. The application code you need to write is clean and clear:
322
335
323
336
```tsx
324
-
// frontend query
325
-
const { data: lists } = useFindManyList(
326
-
{
327
-
where: {
328
-
space: {
329
-
slug: router.query.slug as string,
330
-
},
331
-
},
332
-
}
333
-
);
337
+
// frontend query:
338
+
// ZenStack generated hooks only returns the data user is allowed to read
// ZenStack enhanced Prisma client only returns the data user is allowed to read
346
+
const lists = await db.list.findMany();
345
347
return {
346
348
props: { lists },
347
349
};
348
350
};
349
351
```
350
352
351
-
> The `where` clause above is to get the data from current space because one user could join multiple `Space`. It’s the application behavior instead of Authorization
352
-
>
353
+
> Remember the complex query you need to write for the RLS case mentioned above?
0 commit comments