Back

Adding Phone Number During User Registration in Appwrite

  • 0
  • Auth
  • Web
  • Cloud
JP
4 Feb, 2025, 14:36

Hi everyone

I'm working on integrating user registration in my application and need to include a phone number as a mandatory field. I understand that the account.create() API accepts up to four arguments: user ID, email, password, and name. To incorporate the phone number, I attempted to use the account.updatePhone() method after account creation. However, this approach results in a (role: applications) missing scope (account) error.

Is there a recommended method to include the phone number during the registration process?

Below is the code snippet where the issue occurs: `
.post( "/register", zValidator("json", registerSchema), async (c) => { const { name, email, password, phone } = c.req.valid("json");

TypeScript
        const { account } = await createAdminClient();
        const user = await account.create(
            ID.unique(),
            email,
            password,
            name,
        );

        // Create a session for the newly created user
        const session = await account.createEmailPasswordSession(
            email,
            password,
        );

        // Update the user's phone number
        await account.updatePhone(
            phone,
            password
        );

        setCookie(c, AUTH_COOKIE, session.secret, {
            path: "/",
            httpOnly: true,
            secure: true,
            sameSite: "strict",
            maxAge: 60 * 60 * 24 * 30,
        });

        return c.json({ success: true });
    }
)

`

Any guidance on how to properly include the phone number during registration would be greatly appreciated.

Thank you in advance for your assistance.

TL;DR
Developers want to include a phone number during user registration in Appwrite. Incorporating account.updatePhone() after account creation leads to a missing scope error. To include the phone number during registration, utilize account.create() method with additional field as shown below: Modify the code snippet as follows: ... const { name, email, password, phone } = c.req.valid("json"); const { account } = await createAdminClient(); const user = await account.create( ID.unique(), email, password, name, { phone // Add phone number here } ); // Create a session for the newly created user
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