'Trying to change a phone number in firebase

I'm trying to change a phone number from a user using Firebase. Checked the documentation and haven't found anything. After researching a little i found a stack overflow post where i adapted to my codebase. (How do I update a FirebaseUser's phone number in firebase_auth?)

After a few trials and trying to check the problem i came up with the following error and i don't understand what it means:

FirebaseError: Firebase: Error (auth/argument-error).
    at createErrorInternal (assert.ts:122:1)
    at _assert (assert.ts:153:1)
    at new RecaptchaVerifier (recaptcha_verifier.ts:111:1)
    at onSubmit (Profile.tsx:55:1)
    at onClick (Profile.tsx:94:1)
    at HTMLUnknownElement.callCallback (react-dom.development.js:3945:1)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:3994:1)
    at invokeGuardedCallback (react-dom.development.js:4056:1)
    at invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:4070:1)
    at executeDispatch (react-dom.development.js:8243:1)

here's the code sample:

  const onSubmit = async () => {
    try {
      const userRef = doc(db, "users", auth.currentUser?.uid!);
      if (auth.currentUser?.displayName !== name) {
        await updateProfile(auth.currentUser!, {
          displayName: name,
        });

        await updateDoc(userRef, {
          name: name,
        });
      }
      if (auth.currentUser?.phoneNumber !== phone) {
        var appVerifier = new RecaptchaVerifier(
          "recaptacha-container",
          {
            callback: (response: any) => console.log("callback", response),
            size: "invisible",
          },
          auth
        );
        const phoneProvider = new PhoneAuthProvider(auth);
        const id = await phoneProvider.verifyPhoneNumber(phone!, appVerifier);
        const code = window.prompt(
          "Por favor insira o código enviado para você."
        );
        const credentials = PhoneAuthProvider.credential(id, code!);

        await updatePhoneNumber(auth.currentUser!, credentials);
        console.log("phone number changed", id, credentials, auth.currentUser);

        await updateDoc(userRef, { phone: phone });
      }
    } catch (error) {
      toast.error(`${error}`);
      console.log(error);
    }
  };

Thanks in advance.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source