0

I know that firebase has phone authentication at signing in-up stage. (I need this on android only) But it sends a verification code everytime. Now my application is requires e-mail only when signing in and signing up. What I need is when signing up, user puts his/her phone one time and never deals with verification etc.

Is there any way to do it? Thank you !

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • To get the phone number of a user without having them sign in with it, see https://stackoverflow.com/questions/2480288/programmatically-obtain-the-phone-number-of-the-android-phone – Frank van Puffelen Apr 28 '18 at 14:05

1 Answers1

0

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

Callam
  • 11,409
  • 2
  • 34
  • 32