RLS Examples
Practical Row-Level Security patterns for common application types. Important: Base44 RLS supports:- Logical operators:
$or,$and,$norfor combining conditions - Field operators (for
data.*fields):$in,$nin,$ne,$all - user_condition: Equality only (no operators)
Contents
- Simple Patterns (JSON Schema)
- Using Operators
- Field-Level Security Examples
- Complex Patterns (Dashboard UI or Backend)
- Best Practices
Simple Patterns (JSON Schema)
These patterns work with the JSON schema RLS format.Todo App - Owner-only access
Users see and manage only their own tasks.Contact Form - Public create, admin-only read
Anyone can submit, only admins can view submissions.User Profile - Self-management
Users can only access their own profile.Department Data - Same department access
Users can only see records from their department.Subscription - Admin-managed, user-readable via email field
Private Data - Owner-only
Public Read, Authenticated Write
Anyone can read, only logged-in users can create/edit their own records.Using Operators
Logical Operators
Combine multiple conditions using$or, $and, or $nor:
Owner OR Admin access:
Field Operators for data.* Fields
Use$in, $nin, $ne, $all for comparing entity data fields:
Access based on tags ($in):
Combining Logical and Field Operators
Field-Level Security Examples
Control access to specific fields within an entity.Sensitive Salary Field
Admin-Only Internal Fields
Complex Patterns (Dashboard UI or Backend)
Some patterns may still require the Dashboard UI or backend functions.Bidirectional Relationships (e.g., Friendships, Matches)
Requirement: Either party in a relationship should have access. Now possible with $or:- Entity redesign: Store two records per relationship (one for each party)
- Backend function: Query with custom logic
Complex Business Logic
Requirement: Access depends on multiple entity fields with complex conditions. JSON Schema limitation: While operators help, very complex business logic may still be hard to express. Solution options:- Backend function: Implement custom access logic
- Combine simpler rules: Break complex rules into simpler entity-level and field-level rules
Best Practices
Security Strategy
Use a combination of entity-level RLS and field-level security:| Data Type | Approach | Example |
|---|---|---|
| User-editable | Entity RLS: Owner-only | UserProfile with created_by check |
| Sensitive fields | Field-level RLS | Salary field with HR role check |
| Multi-role access | $or with user_condition | Admin OR Manager access |
| Conditional access | Field operators | $in, $ne on data fields |
| Public content | Entity RLS: read: true | PublicPost |
| Private content | Entity RLS: Owner-only | PrivateNote |
When to Use Each Approach
| Requirement | Approach |
|---|---|
| Single condition (owner, admin, department) | JSON Schema RLS |
| Multiple OR/AND conditions | JSON Schema RLS with $or/$and |
Field value checks with $in/$ne/etc. | JSON Schema RLS for data.* fields |
| Field-level access control | JSON Schema FLS (field-level rls) |
Complex comparison operators ($gt, $lt) | Backend functions |
| Very complex business logic | Backend functions |
Common Role Patterns
| Role | Typical Access |
|---|---|
admin | Full access to all records |
moderator | Read/update access, limited delete |
manager | Department-scoped access |
user | Own records only |
Supported Operators Summary
| Operator | Supported | Notes |
|---|---|---|
$or | Yes | Combine multiple conditions |
$and | Yes | All conditions must match |
$nor | Yes | None of the conditions match |
$in | Yes | For data.* fields only |
$nin | Yes | For data.* fields only |
$ne | Yes | For data.* fields only |
$all | Yes | For data.* fields only |
$gt, $lt, $gte, $lte | No | Use backend functions |
$regex | No | Use backend functions |
Limitations Summary
| Not Supported | Alternative |
|---|---|
Operators on user_condition | Use equality only for user checks |
Comparison operators ($gt, $lt) | Backend functions |
Regex matching ($regex) | Backend functions |
| Cross-entity relationships | Backend functions |

