DeFacedFaceOriginal post
Rank 1: Thread
Registering a user works just fine in my application... Except adding user data to the collection simply does not work. I'm hit with the error :
Registration error: AppwriteException: app....
@service.cloud.appwrite.io (role: applications) missing scope (account)
my code:
import { getLoggedInUser, createUserClient } from "@/lib/server/appwrite";
import { redirect } from "next/navigation";
import { ID } from "appwrite";
import RegisterForm from "@/app/register/registerform";
import { cookies } from "next/headers";
export default async function RegisterPage() {
const user = await getLoggedInUser();
if (user) redirect("/dashboard");
async function handleRegister(formData) {
"use server";
const { account } = await createUserClient();
const {
email,
password,
organization,
missionStatement,
organizationWebsite,
} = formData;
try {
await account.create(ID.unique(), email, password, organization);
const session = await account.createEmailPasswordSession(email, password);
cookies().set("my-custom-session", session.secret, {
path: "/",
httpOnly: true,
sameSite: "Strict",
secure: true,
});
const data = {
organization,
missionStatement,
organizationWebsite,
};
try {
const request = await fetch("/app/api/register", {
method: "POST",
body: data,
});
} catch (error) {
console.error(error);
}
// redirect("/dashboard");
} catch (error) {
console.error("Registration error:", error);
}
}
return <RegisterForm onRegister={handleRegister} />;
}
Summary
Developers are receiving a "missing scope (account)" error when trying to add user data to a collection. The issue seems to be with using an API key incorrectly. The solution is to make sure the API key is set correctly in the createUserClient function.