[SOLVED] Add user permission in the document created using functions
- 0
- Databases
- Flutter
- Functions
Im really sorry but its actually under NDA so wont be possible
lemme try sharing code by removing some part and so
import 'dart:convert';
import 'package:dart_appwrite/dart_appwrite.dart';
Future<void> start(final req, final res) async {
try {
final client = Client()
.setEndpoint('...')
.setProject(Constants.projectId)
.setKey('...')
.setSelfSigned(status: true);
final database = Databases(client);
final payload = req.payload;
final userId = res.variables['APPWRITE_FUNCTION_USER_ID'];
final ... = await database.createDocument(
databaseId: '...',
collectionId: '...',
documentId: '...',
permissions: [
Permission.read(Role.user(userId)),
Permission.update(Role.user(userId)),
Permission.delete(Role.user(userId)),
Permission.create(Role.user(userId)),
],
data: {...}
);
} catch (e) {
res.json({'error': e});
}
}
Would this be enough?
Can you add st to the catch and share it?
} catch (e,st) {
res.json({'error': e,'st':st});
}
Oh Wait a sec
Can you change it to req instead of res?
-res.variables['APPWRITE_FUNCTION_USER_ID'];
+req.variables['APPWRITE_FUNCTION_USER_ID'];
lemme try that
Nope
but now it is giving this error
Converting object to an encodable object failed: Instance of 'AppwriteException'
With what stacktrace?
And upon looking at logs of appwrite
Message: Invalid permissions: Permission "create("user:64ac3b8cf403a8b2ab32")" is not allowed. Must be one of: read, update, delete, write.
this is the exact error
Yes, you shouldn't put create one
You can see in the example
Here
Well, that did worked, but now the permissions in db are duplicated somehow
"read(user:64ac3b8cf403a8b2ab32)", "update(user:64ac3b8cf403a8b2ab32)", "delete(user:64ac3b8cf403a8b2ab32)", "update(user:64ac3b8cf403a8b2ab32)", "delete(user:64ac3b8cf403a8b2ab32)"
this is the response
Yes, I think you can just give the write permission
permissions: [
Permission.write(Role.user(userId)),
],
Or write + read
permissions: [
Permission.read(Role.user(userId)),
Permission.write(Role.user(userId)),
],
Try it
Lemme try it
Thanks a lot, was able to solve it
[SOLVED] Add user permission in the document created using functions
Recommended threads
- [Regression] Appwrite 25.1.0 returns Inv...
I've already opened an issue on GitHub, but somewhat it doesn't seem like GitHub is monitored very closely, so I'm leaving a bug report here on Discord as well....
- Quota not resetting
hi, im using appwrite's free tier plani hit my read limts last month and the billing cycle said it would reset on june 4th but that is today, the billing cycle ...
- Request for temporary 3 to 4 hours datab...
Hi Appwrite Team, I hope you are doing well.We are an early-stage startup currently running on Appwrite Cloud. We have unfortunately exhausted our database rea...