Estoy tratando de crear una aplicación simple que permita iniciar sesión con un número de teléfono, pero parece que no hace absolutamente nada cuando hago clic en el botón que dice "setupCaptcha".
La línea: import firebase from '../firebase' (línea 5) no hace absolutamente nada (no se hace referencia en ninguna parte del código), pero cuando lo comento me da este error: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app). cuando lo elimino, el clic del botón no hace absolutamente nada.
import React from 'react' import { useHistory } from 'react-router-dom' import { MainButton } from '../components/MainButton' import { MainInput } from '../components/MainInput' import firebase from '../firebase' // import { getAuth, RecaptchaVerifier, signinWithPhoneNumber } from "firebase/auth"; import { getAuth, RecaptchaVerifier, signInWithPhoneNumber } from "firebase/auth"; export default function EnterPhoneNumber() { const history = useHistory(); // const phoneNumber = getPhoneNumberFromUserInput(); function setupCaptcha() { const auth = getAuth(); window.recaptchaVerifier = new RecaptchaVerifier('sign-in-button', { 'size': 'invisible', 'callback': (response) => { // reCAPTCHA solved, allow signInWithPhoneNumber. // onSignInSubmit(); onSignInSubmit() } }, auth); } function onSignInSubmit() { const auth = getAuth(); const appVerifier = window.recaptchaVerifier; signInWithPhoneNumber(auth, "+447xxxxxxxxx", appVerifier) .then((confirmationResult) => { // SMS sent. Prompt user to type the code from the message, then sign the // user in with confirmationResult.confirm(code). window.confirmationResult = confirmationResult; // ... }).catch((error) => { // Error; SMS not sent // ... }); } Este es mi archivo firebase.js :
import firebase from 'firebase/compat/app' // import 'firebase/compat/auth' const app = firebase.initializeApp({ apiKey: "xxxxxxx", authDomain: "xxxxxx.firebaseapp.com", projectId: "xxxxxx", storageBucket: "xxxxxxxx.appspot.com", messagingSenderId: "xxxxxxxx", appId: "xxxxxxxxxx" }) // export const auth = app.auth(); export default firebase;