Back

Next js SSR convert anonymous to real account

  • 0
  • Web
veryhealthy
27 Sep, 2024, 10:59

Hello, I am making a anonymous session in next js server side by doing :

TypeScript
export async function createAnon() {
    const client = new Client()
        .setEndpoint(process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT as string)
        .setProject(process.env.NEXT_PUBLIC_APPWRITE_PROJECT as string);

    const account = new Account(client);
    const result = await account.createAnonymousSession();
    return result;
}

then I try to convert the anonymous account to a normal one by doing update mail :

TypeScript
export async function createAccountFromAnon(email: string, password: string) {
    const client = new Client()
        .setEndpoint(process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT as string)
        .setProject(process.env.NEXT_PUBLIC_APPWRITE_PROJECT as string)
        .setSession('current');

    const account = new Account(client);

    const result = await account.updateEmail(
        email,
        password
    );

    return result;
}

and I get the following error :

Error: User (role: guests) missing scope (account) lib/server/appwrite.ts (42:20) @ async createAccountFromAnon

40 | const account = new Account(client); 41 |

42 | const result = await account.updateEmail( | ^ 43 | email, 44 | password 45 | );

I am probably missing something here

TL;DR
Developers are creating an anonymous session in Next.js using Appwrite, then attempting to convert it to a real account by updating the email, but encountering an error related to missing a user scope. The error suggests that the role is set to "guests" instead of "account." To fix this, ensure that the user's role has the necessary scope for updating an email.
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