#missing scope (account)

7 messages · Page 1 of 1 (latest)

shy jungle
#

api route

import {
  Client,
  Databases,
  Account,
  ID,
  Permission,
  Role,
} from "node-appwrite";
import { cookies } from "next/headers";

export async function POST(request) {
  try {
    const cookie = cookies().get("my-custom-session");
    const client = new Client()
      .setEndpoint("https://cloud.appwrite.io/v1")
      .setProject("...")
      .setSession(cookie.value);

    const account = new Account(client);
    const databases = new Databases(client);

    try {
      const user = await account.get();
      const userID = user.$id;
      const data = await request.json();

      const result = await databases.createDocument(
        "...", // databaseId
        "...", // collectionId
        ID.unique(), // documentId
        data,
        [
          Permission.read(Role.user(userID)),
          Permission.write(Role.user(userID)),
        ],
      );

      console.log("Document created:", result);
      return result;
    } catch (err) {
      console.log("Error in document creation:", err);
    }
  } catch (error) {
    console.error("Error creating document:", error);
    throw error;
  }
}
#

missing scope (account)

dense geode
#

you're using an API key somehwere where you shouldn't

shy jungle
# dense geode you're using an API key somehwere where you shouldn't

i'm using an api key here on the server sdk. What should i use instead?

export async function createUserClient() {
  const client = new Client()
    .setEndpoint(process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT)
    .setProject(process.env.NEXT_PUBLIC_APPWRITE_PROJECT)
    .setKey(process.env.NEXT_APPWRITE_KEY);

  return {
    client,
    account: new Account(client),
  };
}
grizzled egret
#

I'm getting the same problem on the server, but using the Python SDK. Following the instructions here, I'm creating a Client and providing the API key. When I attempt to call certain endpoints, e.g. get_session, I get the error

appwrite.exception.AppwriteException: [email protected] (role: applications) missing scope (account)

I don't see any account related scopes available in the API Keys section (see screenshot).

I'm working on a Streamlit app which uses appwite to auth, amongst other things. The Streamlit app backend is where the appwrite Python SDK is being used.

The Account service allows you to authenticate and manage a user account. You can use the account service to update user information, retrieve the user sessions across different devices, and fetch the user security logs with his or her recent activity.

Register new user accounts with the [Create Account](/docs/references/cloud/client-web/accoun...