I would like to know how you do this in Appwrite Databases. Any ideas?
For that, firstly you'll have to set row security via the Console, then you can add the specific permissions via your code .
Can you tell which language or framework you're using?
i use nextjs
thanks
Sure, but since I don't know whether you're using TablesDB or earlier Collection based DB, I'll give you the example for both:
- For
TablesDByou can do something like this:
import { Client, TablesDB, ID, Permission, Role } from "appwrite";
const client = new Client()
.setEndpoint(process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT!)
.setProject(process.env.NEXT_PUBLIC_APPWRITE_PROJECT_ID!);
const tablesDB = new TablesDB(client);
export async function createANewRecord(userId: string) {
return await tablesDB.createRow(
"DATABASE_ID",
"TABLE_ID",
ID.unique(),
{
createdAt: Date.now()
},
[
Permission.read(Role.user(userId)),
Permission.update(Role.user(userId)),
Permission.delete(Role.user(userId))
]
);
}
- And for the
CollectionsDB you can do something like this:
import { Client, Databases, ID, Permission, Role } from "appwrite";
const client = new Client()
.setEndpoint(process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT!)
.setProject(process.env.NEXT_PUBLIC_APPWRITE_PROJECT_ID!);
const databases = new Databases(client);
export async function createANewRecord(userId: string) {
return await databases.createDocument(
"DATABASE_ID",
"COLLECTION_ID",
ID.unique(),
{
createdAt: Date.now()
},
[
Permission.read(Role.user(userId)),
Permission.update(Role.user(userId)),
Permission.delete(Role.user(userId))
]
);
}
This was just an example, instead of that createdAt: Date.now() you can put any other column name + value pair as per your DB schema. Also, you can set different permissions too as per your choice & requirement.
ok, then i am well-prepared. thank you (i am using the new approach: table-based databases)
Recommended threads
- Issue related to index
Why it is showing this error?
- Project paused despite active use — rest...
Hey team! My Appwrite Cloud project (685579e5000d78e67009) has been marked as paused due to inactivity, but it's actively used in production. I clicked the Rest...
- Creation failedUnknown sort order:asc. M...
Hi there, I'm getting this error on self hosted when trying to create an Index. Any ideas?