Skip to content
Back

Is `account.get()` not working in Appwrite cloud functions?

  • 0
  • Auth
  • Web
  • Functions
Chidera Humphrey
11 Mar, 2025, 07:01

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.
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