firebase / snippets-web

Web snippets for firebase.google.com
Apache License 2.0
752 stars 241 forks source link

Phone Number Submission Error on Expo #373

Open farmhutsoftwareteam opened 3 months ago

farmhutsoftwareteam commented 3 months ago

`import React, { useState } from 'react'; import { View, Text, TextInput, Button, StyleSheet } from 'react-native'; import { getAuth, signInWithPhoneNumber } from "firebase/auth"; import app from "../config/firebaseConfig"; import { initializeRecaptcha } from "../config/recaptcha";

const AuthForm = () => { const [phoneNumber, setPhoneNumber] = useState(''); const [confirm, setConfirm] = useState(null); const [code, setCode] = useState('');

const handlePhoneNumberSubmit = async () => { try { const auth = getAuth(app); const recaptchaVerifier = initializeRecaptcha(); const confirmation = await signInWithPhoneNumber(auth, phoneNumber, recaptchaVerifier); setConfirm(confirmation); console.log('SMS sent successfully. Confirmation result:', confirmation); } catch (error) { console.error('Phone Number Submission Error:', error); } };

const handleCodeSubmit = async () => { try { await confirm.confirm(code); console.log('Phone Number Verified!'); } catch (error) { console.error('Code Confirmation Error:', error); } };

return (

{!confirm ? ( <> Enter your phone number: