IamtheFutureOriginal post
Rank 1: Thread
Am using next js
TypeScript
export async function createAdminClient() { 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 { get account() { return new Account(client); }, };}TypeScript
export async function logout(currentState: { message: string }) { try { const { account } = await createAdminClient();
await account.deleteSession("current");
cookies().delete("my-custom-session");
console.log("Logged out successfully");
redirect("/login"); } catch (error) { console.log(error); return { message: "Invalid email or password", }; }}error
{
code: 401,
type: 'general_unauthorized_scope',
response: {
message: 'app.66fe880a001f23a26817@service.cloud.appwrite.io (role: applications) missing scope (account)',
code: 401,
type: 'general_unauthorized_scope',
version: '1.6.0'
}
}
Summary
Issue: Developer is facing a general_unauthorized_scope error when trying to create an admin client and perform logout in a Next.js App using Appwrite.
Solution: The error code 401 suggests an authorization issue. The error message indicates that the role 'applications' is missing the scope 'account'. Developers need to ensure that the necessary scopes are set correctly when creating the admin client and performing actions like logout. This can help resolve the general_unauthorized_scope error.