Back

Node-appwrite

  • 0
  • REST API
  • Web
  • Cloud
zombikaa
2 Dec, 2024, 20:07

And what should i make with functions and what with sdk? Like an auth is safe with sdk?

TL;DR
Developers are discussing how to prevent users from adding custom attributes in Node-appwrite. They also question the best way to make an attribute unchangeable. It's explained that permissions are set at a document level, not attribute level, but custom validations can be implemented. The discussion covers using SDK vs functions, validating user actions, and managing APIs. Ensure permissions are set correctly for safety. Use appwrite SDK for secure client-side handling of functions. It's mentioned that Appwrite automatically handles adding user IDs to headers. Consider using JWT for validation purposes. It's recommended not to have large functions but rather many simpler ones. Documentation and examples
D5
2 Dec, 2024, 20:08

Also, functions validate the user that executes it and automatically adds the user id to the header so you don't need to do additional validations.

D5
2 Dec, 2024, 20:09

You don't need to do Auth. If you're using the SDK to execute the functions and inside them, Appwrite will handle it, and add a header automatically with the ID from the user that is executing it.

zombikaa
2 Dec, 2024, 20:09

But i mean like on a normal website auth, not the functions

D5
2 Dec, 2024, 20:09

You use the appwrite SDK. No need functions or anything

D5
2 Dec, 2024, 20:10

The appwrite SDK and Auth has a built-in API that is safe to use client side

zombikaa
2 Dec, 2024, 20:11

So functions are only for validation right? So everything is safe with sdk only the validation has to go on functions

D5
2 Dec, 2024, 20:11

What kind of validation do you want to perform?

zombikaa
2 Dec, 2024, 20:12

Like when making a post the caption only should be maximum 60 characters etc

D5
2 Dec, 2024, 20:14

I think you don't even need functions for that. Maybe to make sure the user is not spoofing the creator ID, but you set that when creating an attribute in the console πŸ˜…

zombikaa
2 Dec, 2024, 20:15

But i cant make validations only on the client side

D5
2 Dec, 2024, 20:17

If you need custom validations, apart from the size, then yes, you need it. For that, you make a function and pass a payload to it and path.

zombikaa
2 Dec, 2024, 20:17

Okay thanks for your help, ill let you know if i have other questions

zombikaa
2 Dec, 2024, 22:04

@D5, i have a question, if someone only has a read permission to its own documents, if i just make a function that lists the documets in a collection, will the user only see its own documents, or every document?

D5
2 Dec, 2024, 22:19

The function will return all documents by default as it needs an API key

D5
2 Dec, 2024, 22:20

Why not fetching the docs directly on the client side? That will respect permissions

zombikaa
2 Dec, 2024, 22:28

okay, thanks

zombikaa
2 Dec, 2024, 22:29

i tought that the node js / functions way is safer than only the sdk on the client, but thanks πŸ˜…

D5
2 Dec, 2024, 22:36

If you set permissions properly, it should be safe

D5
2 Dec, 2024, 22:37

Note that for now, you can do advanced things such as restricting an attribute

zombikaa
2 Dec, 2024, 22:53

what do you mean by that?

D5
2 Dec, 2024, 23:03

If you set permissions, the will see the entire document they have permission to see. You can't restrict a part of the document

zombikaa
2 Dec, 2024, 23:04

yeah, but i hope they bring that feature in

zombikaa
3 Dec, 2024, 11:20

and what do you think, whats the best way to make an attribute ,,unchangeable", i mean i have an attribute that shouldnt be updated, but the user has update permission

zombikaa
3 Dec, 2024, 11:21

and how can i prevent that someone adds things like user preferences etc, with a custom code

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