Back

Email Authentication gives a 'missing scope (account)' error

  • 1
  • Auth
  • Web
  • Cloud
TheDarkKL
15 Nov, 2024, 22:24

Hi, i am currently creating an app with appwrite but I have an issue. I added verification via email and password to it, which works just fine. But now I want to add Email verification to it, but as soon as i call account.createVerification(<MyURL>) it gives an error:

AppwriteException: &#x2e;&#46;&#46;&#x40;&#115;&#x65;&#114;&#x76;&#x69;&#x63;&#101;&#x2e;&#99;&#x6c;&#111;&#x75;&#100;&#46;&#97;&#x70;&#x70;&#119;&#x72;&#105;&#116;&#x65;&#x2e;&#105;&#x6f; (role: applications) missing scope (account)

TL;DR
Developers are struggling with an 'missing scope (account)' error while trying to implement email verification in their appwrite app. One solution suggested is creating a session client to make the request as a user.
TheDarkKL
15 Nov, 2024, 22:25
TypeScript
export const createAccount = async ({
  fullName,
  email,
  password,
}: {
  fullName: string;
  email: string;
  password: string;
}) => {
  const existingUser = await getUserByEmail(email);

  if (!existingUser) {
    const { databases, account } = await createAdminClient();

    try {
      const user = await account.create(ID.unique(), email, password, fullName);
      const accountId = user.$id;

      await databases.createDocument(
        appwriteConfig.databaseId,
        appwriteConfig.usersCollectionId,
        ID.unique(),
        {
          fullName,
          email,
          avatar: avatarPlaceholderUrl,
          accountId,
        }
      );

      const session = await account.createEmailPasswordSession(email, password);
      (await cookies()).set("APPWRITE_SESSION", session.secret, {
        path: "/",
        httpOnly: true,
        sameSite: "strict",
        secure: true,
      });

      await account.createVerification("http://localhost:3000/verify");

      return parseStringify({ accountId });
    } catch (error) {
      handleError(error, "Failed to create account");
    }
  }
  return parseStringify({ message: "User already exists" });
};
Steven
15 Nov, 2024, 22:26

Role: applications means you're using an API key. But you're trying to make a request that needs to be done as a user (scope account)

TheDarkKL
15 Nov, 2024, 22:30

Okay, but how can I do it as a user then? That is what I don't find

Steven
15 Nov, 2024, 22:54

Maybe you can try creating the session client and using that

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