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
- MongoDb Database Breaks integer[] & bigi...
I've got a table with the below column created. When I try to insert the value `[-3408048000]` into it, the dart sdk cloud function call is successful (no error...
- Appwrite Functions cold start
Hello. I'm seeing really long cold starts on Appwrite Cloud Functions and wanted to know if this is expected. My function just authenticates the user, fetches ...
- Error can not create `tablesdb` event wi...
When i'm trying to add an event with `tablesdb` i get an error message My event value: `tablesdb.mtg-decklist-dev.tables.queue_parsing.rows.*.create` Same err...