Hire someone for custom code

Custom Code

I am looking for someone who can write custom code for an action the can help me with the following scenario:

Generally the user authenticates and login to my app using phone Auth (firebase) but in the future if the user wants to change his phone number he should be able to change his phone number while having the same UID in firebase authentication.

Currently I have a custom code that sends an OTP on the new phone number, and I also fetch the verification ID which is required later to update the number, but I couldn't find a way to update the current authenticated user phone number.

If anyone is willing to do it I can pay for it.

What have you tried so far?
import 'package:firebase_auth/firebase_auth.dart';

Future<bool> verifyOTP(String otpCode, String? verificationId) async {
  final auth = FirebaseAuth.instance;

  if (verificationId == null) {
    print('Error: Verification ID not available. Please request a new OTP.');
    return false;
  }

  try {
    final PhoneAuthCredential phoneAuthCredential =
        PhoneAuthProvider.credential(
            verificationId: verificationId, smsCode: otpCode);

// Sign in the user with the credential
    final userCredential = await auth.signInWithCredential(phoneAuthCredential);

// Ensure the user is authenticated and not a new user
    if (userCredential.user != null &&
        userCredential.additionalUserInfo!.isNewUser == false) {
      try {
// Check if the authenticated user's UID matches the UID in the credential
        if (userCredential.user!.uid == phoneAuthCredential.providerId) {
// Update the phone number of the authenticated user
          await userCredential.user!.updatePhoneNumber(phoneAuthCredential);
          print(
              'Phone number updated successfully for user: ${userCredential.user!.uid}');
          return true; // Indicate successful verification and update
        } else {
          print('Error: User UID does not match credential provider ID.');
          return false; // Indicate UID mismatch error
        }
      } on FirebaseAuthException catch (error) {
        print('Update phone number failed: ${error.code}');
        return false; // Indicate update failure
      }
    } else {
      print('Error: User not authenticated or new user created.');
      return false; // Indicate authentication failure or new user creation
    }
  } on FirebaseAuthException catch (error) {
    print('Verification failed: ${error.code}');
    return false; // Indicate verification failure
  }
}
Did you check FlutterFlow's Documentation for this topic?
Yes
1
1 reply