Back

how React Native Query with API key

  • 0
  • Self Hosted
  • React Native
  • Tools
  • Databases
Suiii
17 Jan, 2025, 13:49

how to perform acton to collectons which React Native SDK user having no permission.

actually, I can give them permissons but considering it would be redudancy and wastes of resources as well as performances. I decided for nextjs (node-apwrite), I only give permission document level to Clients collection. By doing that, other collections which are considered using clients collection as FK, will be based on to verify the permissions.

Based on code below, I can do that fine on NextJS server action, but I would like to do the same for react native but I also understand RN is client framework. so what is the workaround for this

TypeScript
export async function queryHealthRecords(clientId: string): Promise<ActionResult<HealthRecords>> {
  
 // check if user can access by finding specific document of Clients collection to see its permission against logged in user
  const hasPermission = await hasPermissionByClient(clientId)
  if (!hasPermission) return []

  const db = await createAdminDB()
  const models = await db.healthRecords.list([Query.equal("clientId", clientId), Query.limit(maxQueryLimit), Query.orderDesc("recordDate")])
  return await Promise.all(models.documents.map(async (model: any) => await mapToHealthRecordDto(model)))

}
TL;DR
Developers want to set up query permissions in a React Native app similar to a NextJS server. They only want to grant permissions at the document level for one collection to avoid redundancy and performance issues. The code provided checks if the user has permission before querying health records by client ID. To achieve a similar setup in React Native (a client framework), developers would need to implement a similar permission check logic on the client-side with suitable security measures.
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more