Back

How can i hide private attributes from a collection?

  • 1
  • Web
  • Storage
Zsombor
8 Oct, 2024, 13:43

Im creating a site where people can post, but there are some attributes like likes that i dont want people to see

TL;DR
There is an option to use `Query.select(attribute)` to choose specific attributes, but this may not fully prevent access to private attributes. Alternatively, you can create a cloud function that fetches the data and returns only the desired attributes.
Kenny
8 Oct, 2024, 13:45

You can use Query.select(attribute) to select only the attributes you want, but this doesn't stop anyone from altering the request to get everything. Other than that you can create a cloud function that you call via rest, that does the fetching and returns only exactly what you want

Zsombor
8 Oct, 2024, 13:46

Yeah i checked a video about the functions but i couldnt really get to anywhere with it

Kenny
8 Oct, 2024, 13:48

What issues are you having?

Kenny
8 Oct, 2024, 13:52

You should be able to use the starter template to get something put together pretty quickly

TypeScript
import { Client, Users } from 'node-appwrite';

export default async ({ req, res, log, error }) => {
  const client = new Client()
    .setEndpoint(process.env.APPWRITE_FUNCTION_API_ENDPOINT)
    .setProject(process.env.APPWRITE_FUNCTION_PROJECT_ID)
    .setKey(process.env.APPWRITE_FUNCTION_API_KEY);
  const database = new Databases(client);

  const { documents } = await database.listDocuments(DATABASE_ID, COLLECTION_ID);

  return res.json({
    attribute: documents.attribute,
    attribute: documents.attribute,
    attribute: documents.attribute
  });
};
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