Create a Cloud Function you can trigger from the client to update the user's phone number using the Firebase Admin SDK – you can use callable functions to easily trigger them from the client.
import * as admin from 'firebase-admin';
import * as functions from 'firebase-functions';
admin.initializeApp();
export const updatePhoneNumber = functions.https.onCall(async (data, context) => {
if (!context.instanceIdToken) {
throw new functions.https.HttpsError(
'failed-precondition',
'The function must be called while authenticated.'
);
}
if (typeof data !== 'string' || data.length === 0) {
throw new functions.https.HttpsError(
'invalid-argument',
'The function must be called with a phone number.'
);
}
const verifiedToken = await admin.auth().verifyIdToken(context.instanceIdToken, true);
const userRecord = await admin.auth().updateUser(context.auth.uid, { phoneNumber: data });
return userRecord.toJSON();
});
Calling the function from your App is shown here – https://firebase.google.com/docs/functions/callable#call_the_function