I'm trying to get the current user in my Appwrite function but I'm getting this error: AppwriteException: app.677c6d970016b1973c68@service.cloud.appwrite.io (role: applications) missing scope (account)
Why is that?
Here's my code:
TypeScript
const { Client, Account } = require('node-appwrite');
const { Permit } = require('permitio');
if (triggerType === 'event' && data.bucketId) {
try {
const account = new Account(client);
const user = await account.get();
await permit.api.resourceInstances.create({
resource: "file",
key: data.$id,
tenant: "default",
});
const resource_instance = `file:${data.$id}`;
await permit.api.roleAssignments.assign({
user: user?.email,
role: 'owner',
resource_instance,
});
return res.json({
ok: 'success',
message: `Resource instance created and the owner is ${user?.name}`,
});
} catch (err) {
error(err);
return res.json({
ok: 'fail',
message: `There was error adding file resource`,
});
}
}
TL;DR
Issue: Error `AppwriteException: app.677c6d970016b1973c68@service.cloud.appwrite.io (role: applications) missing scope (account)` when trying to use `account.get()` in Appwrite cloud function.
Solution: The error occurs because the user does not have the required scope. Make sure the user has the `account` scope assigned.Recommended threads
- dynamic key missing scopes for database ...
Here are the scopes listed, I get permission errors for reading row and document. Appears to be missing since last time i checked. Database 6 Scopes policies....
- No server error on selfhosted appwrite
Please help me, my clients is ask what happen on their data? How can i make it up again?
- Worker functions stuck on "Fetched 0 fun...
Appwrite Version: 1.9.0 Bug Description: The appwrite-worker-functions container gets stuck in an infinite loop logging "Fetched 0 functions..." while scheduled...