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
- Getting current user has been blocked
Getting current user has been blocked error while signing in the appwrite console. Got this during I am testing with the my saas web project. Please help to unb...
- vorafy.studio domain already exists erro...
My domain vorafy.studio is stuck/locked from a previously deleted project. I created a new project but can't add the domain — getting 'already exists' error. Pl...
- Appwrite-injected variables are not avai...
I am using rust-1.83 as a runtime and try to access APPWRITE_FUNCTION_API_ENDPOINT or APPWRITE_FUNCTION_API_KEY during runtime. Both are not set during my execu...