Secure access scopes at the document level. When setting up a collection, specify RLS parameters:
Read and write access is open using the Public API Key header.
Only verified logged-in users with a valid Bearer token can access.
Users can read and write only documents matching their user ID.
Specify RLS scopes for read/write behaviors inside your collection schema configurations. Supported scopes are "public", "authenticated", and "owner":
{
"name": "posts",
"rules": {
"read": "public", // Anyone can read posts
"write": "authenticated" // Only logged-in users can write posts
}
}
{
"name": "user_profiles",
"rules": {
"read": "owner", // Only the profile owner can read
"write": "owner" // Only the profile owner can modify
}
}// RLS Rule: read = "public", write = "public"
// Anyone can write to this feedback collection without signing in
const newFeedback = await baas.collection("feedbacks").create({
email: "anonymous@user.com",
message: "Love the speed!",
});// RLS Rule: read = "owner", write = "owner"
// When creating documents, Kroxt automatically assigns the current user ID as ownerId
const privateNote = await baas.collection("private_notes").create({
content: "Strictly confidential notes",
});
// Querying owner collections returns only documents owned by the logged-in user
const myNotes = await baas.collection("private_notes").get();If an unauthenticated client triggers an action blocked by RLS rules, the request is rejected with a `403 Forbidden` error:
try {
// Attempting write to an Authenticated/Owner collection without login:
await baas.collection("protected_data").create({ text: "Hello" });
} catch (error: any) {
console.error("Status:", error.status); // 403
console.error("Message:", error.message); // "RLS: Forbidden on write"
}