Search code examples
reactjsfirebasefirebase-authenticationfirebaseui

how to I get the user phone number after verification in react using firebase phone auth


import React from "react";
import StyledFirebaseAuth from 'react-firebaseui/StyledFirebaseAuth';
import firebase from "firebase";
import './firebaseui-styling.global.css';

const config = {
  // My firebase config
};

firebase.initializeApp(config);



const PhoneVerification = () => {

    const uiConfig = {
        signInFlow: 'popup',
        signInOptions: [
            {
                provider: firebase.auth.PhoneAuthProvider.PROVIDER_ID,
                recaptchaParameters: {
                    type: 'image',
                    size: 'invisible',
                    badge: 'bottomleft'
                },
                defaultCountry: '+91',
                whitelistedCountries: ['IN', '+91']
            }
        ],
    }

    return (
        <div>
            <StyledFirebaseAuth uiConfig={uiConfig} firebaseAuth={firebase.auth()} />
        </div >
    )
}

export default PhoneVerification

How can I get the user entered phone number as I want to store it into the database and I am using this just for verification and not for authenticating the user


Solution

  • you'll get phone number in user object

     callbacks: {            
                    signInSuccessWithAuthResult: function (authResult) {
                        var user = authResult.user;
                        console.log(user.phoneNumber)
                    }
                }