Back

[CLOSED] Permissions - Is it possible to use Appwrite without rolling your own Functions or backend?

  • 0
  • Self Hosted
  • Functions
  • Web
Binyamin
17 Jul, 2023, 15:34

This feature request is seems like relevant to that use-case https://github.com/appwrite/appwrite/issues/4656

TL;DR
The user is discussing using Appwrite without rolling their own Functions or backend. They mention their desire to create an "Extended Permissions" Community Extension and a Collection helper. It is clarified that CRUD operations can be performed using a custom Function, but the user must handle user validations themselves. The user expresses interest in a global permissions system like Firebase and mentions a feature request for this functionality. No solution is provided in the thread.
Binyamin
17 Jul, 2023, 15:34

Yes, exactly.

Binyamin
17 Jul, 2023, 15:34

In Appwrite - as of now - you'll have to do it using a function.

skavank
17 Jul, 2023, 15:35

This conversation does confirm my findings. It's absolutely fine, but it does mean that Appwrite (currently) cannot be used safely in production for apps that has personalized user content, unless you roll your own CRUD operations with user validations. Appwrite has many other amazing features however.

Binyamin
17 Jul, 2023, 15:36

Why not?

Binyamin
17 Jul, 2023, 15:36

You can use functions

skavank
17 Jul, 2023, 15:36

Yes, that was my "unless".

skavank
17 Jul, 2023, 15:36

πŸ˜„

Binyamin
17 Jul, 2023, 15:36

πŸ˜‚

Binyamin
17 Jul, 2023, 15:37

You can though use a function and let it be triggered after update, so you can keep using the SDK as usual But verify those fields after create or update events.

skavank
17 Jul, 2023, 15:37

it's a caveat, it's a bit of a hassle, but it's something you'd from a traditional user content creation backend.

skavank
17 Jul, 2023, 15:39

The dream would be to completely remove the propriatary backend code, maybe in the future πŸ™‚

Binyamin
17 Jul, 2023, 15:40

Also this line of Firebase permissions system

TypeScript
allow write : if user.id === document.id

Can be considered to be as a function, it just syntactic sugar for that logic inside Appwrite function.

TypeScript
const docuemnt = req.variables['APPWRITE_FUNCTION_EVENT_DATA'];
const user     = req.variables['APPWRITE_FUNCTION_USER_ID']

if (document.userId !=== user.$id) {
  document.userId =  user.$id;
  
  // Or just return
  res.json({access:false});
  return;
}

Meaning. think of it like this the only different between Firebase and Appwrite in that matter is that in Firebase you need to write it in there permission editor and in Appwrite you need to write it inside a deployed function.

skavank
17 Jul, 2023, 15:42

indeed, there's one other caveat though, Firebase extends these permissions globally. So whenever a new feature is dropped, you can update all document permissions accordingly in one go with a click. In Appwrite, we'd need to write a migration script to migrate all permissions affected for nth documents.

skavank
17 Jul, 2023, 15:43

and we'll need to use a mix between the Permissions in Appwrite, and our custom logic in the Function.

skavank
17 Jul, 2023, 15:45

I have already started on a helper library for generating a full CRUD function callback.

Binyamin
17 Jul, 2023, 15:45

πŸ‘

Binyamin
17 Jul, 2023, 15:46

But keep in mind that you don't need to cover

  • read
  • delete As those will be prefect to be used permission-based.
Binyamin
17 Jul, 2023, 15:46

So you need only CU

skavank
17 Jul, 2023, 15:47
TypeScript
// function.js
import { crud } from 'appwrite-xxx'

module.exports = (req,res) => crud(req, res, 'database', 'collection', {
  create: ({user, document}) => user.id === document.id,
  ...
})
skavank
17 Jul, 2023, 15:49

I might also make a Collection helper, so that I won't have to write db.createDocument('database', 'collection', ...) all the time, just myCollection.create({...})

skavank
17 Jul, 2023, 15:50

Thanks for clarifying. I wanted to make sure I didn't start on some unecessary journey.

Binyamin
17 Jul, 2023, 15:51

πŸ‘ From what I know this is the current stand from Appwrite side.

skavank
17 Jul, 2023, 15:51

Again, really impressed by the features in Appwrite. Perhaps if we get Community Extensions at some point I will make one for "Extended Permissions". Gotta brush off that PHP.

skavank
17 Jul, 2023, 15:59

[CLOSED] Permissions - Is it possible to use Appwrite without rolling your own Functions or backend?

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