undefined is not an object (evaluating '_this2.props') onPress - firebase

React native beginner here, Im trying to pass from login to HomeTeacher/HomeParent, according to the status in the database (firestore). When I'm printing the status, he is good ("Teacher"/"Parent"), but it doesnt go the HomeParent/HomeTeacher
When I press on the button I get the "Error getting document: [TypeError: undefined is not an object (evaluating '_this2.props.navigation')]" error...
Here is my code :
import React from 'react';
import { ImageBackground,Image, TouchableOpacity, StyleSheet, Text, View,TextInput,Dimensions } from 'react-native';
import background from "../Images/background.jpg";
import Logo from "../Images/Independo.png";
import firebase, { firestore } from 'firebase/app';
import { ThemeProvider } from 'react-native-elements';
require('firebase/auth')
require('firebase/firestore')
const {width : WIDTH } = Dimensions.get('window')
const screenHeight=Dimensions.get('window').height
const screenWidth=Dimensions.get('window').width
class LoginAdult extends React.Component {
constructor(props){
super(props)
this.state={
email:'',
password:'',
// status:''
}
}
LoginPress= async()=>{
const {email,password,}=this.state;
if(this.state.email && this.state.password)
{firebase.auth().signInWithEmailAndPassword(email,password)
.then(firebase.auth().onAuthStateChanged(function(user)
{
if (user != null)
{
var docRef=firebase.firestore().collection("Users").doc(user.uid);
docRef.get().then((doc) => {
if (doc.exists) {
console.log("Document data:", doc.data());
const {status} = doc.data();
if(status=="Teacher")
{
console.log("status = ",status)
this.props.navigation.navigate("HomeTeacher")
}
else if(status=="Parent")
{
this.props.navigation.navigate("HomeParent")
}
} else {
console.log("No such document!");
}
}).catch((error) => {
console.log("Error getting document:", error);
});
}
}))
.catch((error)=>{
switch(error.code)
{
case 'auth/invalid-email':
alert("Please, enter a valid mail")
break;
case 'auth/user-not-found':
alert('A user with this email doesnt exist, please sign Up')
break;
}
})
}
else{
alert("Please enter email and password!")
}
}
render(){
return (
<ImageBackground source={background} style={styles.imagebackground}>
<View style={{header:25,backgroundColor:"",alignItems:'center',marginTop:40}}>
<Image source={Logo} style={styles.logo}/>
</View>
<View style={{flex:1,borderWidth:0,borderColor:'transparent',margin:40,marginTop:0,marginBottom:220}}>
<View style={{flex:1,backgroundColor:"#F9f3fc",alignItems:'center',paddingTop:35,borderRadius:15,borderStyle:'dotted solid double'}}>
<Text style={{fontWeight:'bold',fontSize:30,paddingBottom:30}}>LOGIN</Text>
<TextInput
style={styles.input}
placeholderTextColor={'black'}
placeholder={'Email'}
onChangeText={inputEmail=>this.setState({email:inputEmail})}/>
<TextInput
style={styles.input}
placeholderTextColor={'black'}
placeholder={'Password'}
secureTextEntry={true}
onChangeText={inputPassword=>this.setState({password:inputPassword})}/>
<TouchableOpacity style={styles.btnLogin} onPress={()=>this.LoginPress()}>
<Text style={{fontWeight:'600'}}>Login</Text>
</TouchableOpacity>
<TouchableOpacity
style={{alignItems:'center',flexDirection:'row'}}
onPress={()=>this.props.navigation.navigate("SignUp")}>
<Text>Dont have an account? </Text>
<Text style={styles.text}>Sign Up</Text>
</TouchableOpacity>
<TouchableOpacity
style={{alignItems:'center',flexDirection:'row',margin:4}}
onPress={()=>this.props.navigation.navigate("ForgotPasswordAdult")}>
<Text style={{textDecorationLine:'underline' ,fontSize:16 ,fontWeight:'bold',}}>
Forgot Password?
</Text>
</TouchableOpacity>
</View>
</View>
</ImageBackground>
);
}
}
export default LoginAdult;

Related

Error: [auth/unknown] Cannot create PhoneAuthCredential without either verificationProof, sessionInfo, temporary proof, or enrollment ID

I am trying to make a Login page with Phone Authentication to use React-Native-Firebase sdk and I receive OTP through sms and when I confirm the received OTP ,I got a error that: [Error: [auth/unknown] Cannot create PhoneAuthCredential without either verificationProof, sessionInfo, temporary proof, or enrollment ID.]
I am using-
React:18.0.0
React-Native: 0.69.1
React-Native-Firebase:^15.1.1
My code is-
import React, {useState} from 'react';
import {
View,
Text,
StyleSheet,
Image,
TextInput,
TouchableOpacity,
Alert,
} from 'react-native';
import PhoneInput from 'react-native-phone-number-input';
import auth from '#react-native-firebase/auth';
const Login = () => {
const [PhoneNumber, setPhoneNumber] = useState('');
const [otpInput, setOtpInput] = useState('');
const [confirmData, setConfirmData] = useState('');
const sendOtp = async () => {
try {
const responce = await auth().signInWithPhoneNumber(PhoneNumber);
setConfirmData(responce);
console.log(responce);
Alert.alert('Otp is sent please varify it');
} catch (error) {
console.log(error);
}
}
const submitOtp = async () => {
try {
const responce = await confirmData.confirm(otpInput);
console.log(responce);
Alert.alert('Your Number is verified');
} catch (error) {
console.log(error);
}
}
return (
<View>
<View style={styles.con}>
<Text style={styles.container}>Login Screen</Text>
<Image source={require('../assets/logo.png')} style={styles.image} />
</View>
<View style={styles.inputContainer}>
<Text style={styles.labels}>Phone Number:</Text>
<PhoneInput
style={styles.inputStyle}
defaultValue={PhoneNumber}
defaultCode="DM"
layout="first"
keyboardType="number-pad"
onChangeFormattedText={text => setPhoneNumber(text)}
onChangeText={(value) => setPhoneNumber(value)}
/>
</View>
<View>
<TouchableOpacity
style={styles.buttonStyle}>
<Text style={styles.buttonText}>Verify</Text>
</TouchableOpacity>
</View>
<View style={styles.otpContainer}>
<TextInput
style={styles.otpStyle}
placeholder="Enter OTP"
autoCapitalize="none"
secureTextEntry={true}
onChangeText={(value) => setOtpInput(value)}/>
</View>
<View>
<TouchableOpacity style={styles.continueStyle}>
<Text
style={styles.buttonText}
onPress={() => submitOtp()}>
Continue
</Text>
</TouchableOpacity>
</View>
</View>
);
};
export default Login;

TypeError: _this2.somefunction not a function

I'm trying to retrieve the status (parent/teacher/child) of the user I want to log in using the function checkStatusLogin, to redirect the user to the corresponding page
The problem is that I'm getting this error my console : Error getting document: [TypeError: _this2.checkStatusLogin is not a function. (In '_this2.checkStatusLogin(status)', '_this2.checkStatusLogin' is undefined)]
Here is my code :
import React from 'react';
import { ImageBackground,Image,ActivityIndicator, TouchableOpacity, StyleSheet, Text, View,TextInput,Dimensions } from 'react-native';
import background from "../Images/background.jpg";
import independoLogo from "../Images/Independo.png";
import firebase from 'firebase/app';
require('firebase/auth')
require('firebase/firestore')
const {width : WIDTH } = Dimensions.get('window')
const screenHeight=Dimensions.get('window').height
const screenWidth=Dimensions.get('window').width
class LoginAdult extends React.Component {
constructor(props){
super(props)
this.state={
email:'',
password:'',
isLoading:false,
}
this.checkStatusLogin=this.checkStatusLogin.bind(this);
}
checkStatusLogin(status)
{
alert("The user logged in");
console.log("checkStatus = ",status);
if(status==="Parent")
{
console.log("checkStatusParent = ",status);
this.props.navigation.navigate("HomeParent");
}
if(status==="Teacher")
{
console.log("checkStatusTeacher = ",status);
this.props.navigation.navigate("HomeTeacher");
}
if(status==="Child")
{
console.log("checkStatusTeacher = ",status);
this.props.navigation.navigate("HomeChild");
}
}
LoginPress= async()=>{
const {email,password,}=this.state;
global.stat;
if(this.state.email && this.state.password)
{
await firebase.auth().signInWithEmailAndPassword(email,password)
.then(firebase.auth().onAuthStateChanged(function(user)
{
if (user != null)
{
var docRef=firebase.firestore().collection("Users").doc(user.uid);
docRef.get().then((doc) => {
if (doc.exists) {
console.log("Document data:", doc.data());
const {status} = doc.data();
console.log("Status = ",status);
this.checkStatusLogin(status);
} else {
console.log("No such document!");
}
}).catch((error) => {
console.log("Error getting document:", error);
});
}
}))
.catch((error)=>{
switch(error.code)
{
case 'auth/invalid-email':
alert("Please, enter a valid mail")
break;
case 'auth/user-not-found':
alert('A user with this email doesnt exist, please sign Up')
break;
}
}
)
}
else{
alert("Please enter email and password!")
}
}
render(){
return (
<ImageBackground source={background} style={styles.imagebackground}>
<View style={{header:25,backgroundColor:"",alignItems:'center',marginTop:40}}>
<Image source={independoLogo} style={styles.logo}/>
</View>
<View style={{flex:1,borderWidth:0,borderColor:'transparent',margin:40,marginTop:0,marginBottom:220}}>
{this.state.isLoading?
<View style={{alignItems:'center',justifyContent:'center',zIndex:1000,elevation:1000}}>
<ActivityIndicator size="large" color="black"/>
</View>
:null}
<View style={{flex:1,backgroundColor:"#F9f3fc",alignItems:'center',paddingTop:35,borderRadius:15,borderStyle:'dotted solid double'}}>
<Text style={{fontWeight:'bold',fontSize:30,paddingBottom:30}}>LOGIN</Text>
<TextInput
style={styles.input}
placeholderTextColor={'black'}
placeholder={'Email'}
onChangeText={inputEmail=>this.setState({email:inputEmail})}/>
<TextInput
style={styles.input}
placeholderTextColor={'black'}
placeholder={'Password'}
secureTextEntry={true}
onChangeText={inputPassword=>this.setState({password:inputPassword})}/>
<TouchableOpacity style={styles.btnLogin} onPress={()=>this.LoginPress()}>
<Text style={{fontWeight:'600'}}>Login</Text>
</TouchableOpacity>
<TouchableOpacity
style={{alignItems:'center',flexDirection:'row'}}
onPress={()=>this.props.navigation.navigate("SignUp")}>
<Text>Dont have an account? </Text>
<Text style={styles.text}>Sign Up</Text>
</TouchableOpacity>
<TouchableOpacity
style={{alignItems:'center',flexDirection:'row',margin:4}}
onPress={()=>this.props.navigation.navigate("ForgotPasswordAdult")}>
<Text style={{textDecorationLine:'underline' ,fontSize:16 ,fontWeight:'bold',}}>
Forgot Password?
</Text>
</TouchableOpacity>
</View>
</View>
</ImageBackground>
);
}
}
export default LoginAdult;
const styles = StyleSheet.create({
});
Try removing the following line from your our code
this.checkStatusLogin = this.checkStatusLogin.bind(this);
delete the bind function and use an arrow function :
checkStatusLogin= (status) { ... }

How to pull key from firebase realtime database and pass to edit screen?

I am pretty new to react native/firebase, and am trying to figure out how to grab the unique key from an entry in the database (they are randomly generated when using Push), so I can update the database entry on my edit screen. Any help or direction on how I could accomplish this is very much appreciated.
Here is my main feed screen where all items from the database are grabbed and displayed:
let ref = db.ref('dogs');
export default class Main extends React.Component {
_isMounted = false;
constructor() {
super();
this.state = {
currentUser: null,
errorMessage: null,
items: [],
key: '',
};
}
componentDidMount() {
this._isMounted = true;
const {currentUser} = firebaseAuth;
this.setState({currentUser});
ref.on('value', snapshot => {
if (this._isMounted) {
let data = snapshot.val();
let items = Object.values(data);
this.setState({items});
}
});
}
componentWillUnmount() {
this._isMounted = false;
}
render() {
const {currentUser} = this.state;
return (
<View style={styles.container}>
<View>
<View style={styles.container}>
{this.state.items.length > 0 ? (
<ItemComponent
style={styles.listDog}
items={this.state.items}
navigation={this.props.navigation}
/>
) : (
<Text>No dogs</Text>
)}
</View>
<View style={styles.bottomContainer}>
<TouchableOpacity
style={styles.addBtn}
onPress={() => this.props.navigation.navigate('dogCreation')}>
<View>
<FontAwesomeIcon style={styles.penIcon} icon={faBone} />
</View>
</TouchableOpacity>
</View>
</View>
</View>
);
}
}
here is my item component:
export default class ItemComponent extends Component {
static propTypes = {
items: PropTypes.array.isRequired,
};
render() {
return (
<View style={styles.itemsList}>
{this.props.items.map((item, dog) => {
return (
<TouchableOpacity
key={dog}
onPress={() =>
this.props.navigation.navigate('Profile', {
name: item.name,
image_uri: item.image_uri,
parent: item.parent,
parentEmail: item.parentEmail,
parentTwo: item.parentTwo,
parentTwoEmail: item.parentTwoEmail,
})
}>
<View style={styles.dogCard}>
<Image source={{uri: item.image_uri}} style={styles.dogImage} />
<Text style={styles.itemtext}>{item.name} </Text>
<FontAwesomeIcon style={styles.chevron} icon={faChevronRight} />
</View>
</TouchableOpacity>
);
})}
</View>
);
}
}
here is my profile page:
export default class Profile extends React.Component {
render() {
const {navigation} = this.props;
const dogName = navigation.getParam('name', '');
const image_uri = navigation.getParam('image_uri', '');
const parent = navigation.getParam('parent', '');
const parentEmail = navigation.getParam('parentEmail', '');
const parentTwo = navigation.getParam('parentTwo', '');
const parentTwoEmail = navigation.getParam('parentTwoEmail', '');
return (
<View style={styles.container}>
<Image style={styles.dogImage} source={{uri: image_uri}} />
<View style={styles.contentBlock}>
<Text style={styles.header}>Name</Text>
<Text style={styles.textStyle}>{dogName}</Text>
</View>
<View style={styles.contentBlock}>
<Text style={styles.header}>Pet Parent 1 Info</Text>
<Text style={styles.subHeader}>Name</Text>
<Text style={styles.textStyle}>{parent}</Text>
<Text style={styles.subHeader}>Name</Text>
<Text style={styles.textStyle}>{parentEmail}</Text>
</View>
<View style={styles.contentBlock}>
<Text style={styles.header}>Pet Parent 2 Info</Text>
<Text style={styles.subHeader}>Name</Text>
<Text style={styles.textStyle}>{parentTwo}</Text>
<Text style={styles.subHeader}>Name</Text>
<Text style={styles.textStyle}>{parentTwoEmail}</Text>
</View>
<TouchableOpacity
style={styles.addBtn}
onPress={() =>
this.props.navigation.navigate('editProfile', {
name: dogName,
image_uri: image_uri,
parent: parent,
parentEmail: parentEmail,
parentTwo: parentTwo,
parentTwoEmail: parentTwoEmail,
})
}>
<Text>EDIT</Text>
</TouchableOpacity>
</View>
);
}
}
and here is my edit profile page update function:
let ref = db.ref('dogs');
let addItem = (
dog,
parent,
parentEmail,
parentTwo,
parentTwoEmail,
image_uri,
) => {
db.ref('/dogs/')
.update({
name: dog,
parent: parent,
parentEmail: parentEmail,
parentTwo: parentTwo,
parentTwoEmail: parentTwoEmail,
image_uri: image_uri,
});
};
just use on return snapshot return snapshot.key.
ref.on('value', snapshot => {
if (this._isMounted) {
let id = snapshot.key;
let data = snapshot.val();
let items = Object.values(data);
this.setState({items});
}
});
you can see more details here: https://firebase.google.com/docs/reference/js/firebase.database.DataSnapshot#key
**some important points, if you are using the firebase library directly in react native, I advise you to use the version created specifically for React Native, which corrects several problems of timers within the OS.
you can see here: https://rnfirebase.io/
**other importante detail, your firebase return function is a listener, and using this._isMounted is anti patern. you can use subscriber to stop the listener.
so...
let subscriber;
...
componentDidMount() {
const {currentUser} = firebaseAuth;
this.setState({currentUser});
subscriber = ref.on('value', snapshot => {
let data = snapshot.val();
let items = Object.values(data);
this.setState({items});
});
}
componentWillUnmount() {
// Stop listening for updates when no longer required
this.subscriber();
}

getting lat/long coordinates from firebase/firestore collection

im relative new to react native and firebase and it would be awesome if anyone could help me with this problem. currently when im adding new posts to my firebase collection i display all post with a flatlist and it works fine. but is it possible to get only the currentLatitude and currentLongitude for my markers? my target is to generate a new marker for each post.
Events = []
this.firestore.collection("Events").get().then(snapshot => {
snapshot.forEach(doc => {
Events.push(doc.data())
})
})
render() {
return (
<SafeAreaView style={{ flex: 1 }}>
<View style={{ flex: 1 }}>
<MapView
provider={PROVIDER_GOOGLE}
mapType='hybrid'
showsUserLocation style={{flex: 1}}>
<MapView.Marker
coordinate={{latitude: //currentLatitude,
longitude: //currntLongitude}}
title={("Test")}
description={("Test")}
/>
</MapView>
</View>
</SafeAreaView>
);
}
}
#DevAS thanks for your patience.. this was made from 3 different .js files.. but I don't now how to get it just into the map.js.
The final result should look something like this:
enter image description here
Everything except for the lat/lng cords are supposed to be in the callout-window.
Item.js:
import { Ionicons } from '#expo/vector-icons';
import React from 'react';
import { Image, StyleSheet, Text, View } from 'react-native';
import Fire from '../screens/Fire'
const profileImageSize = 36;
const padding = 12;
export default class Item extends React.Component {
state = {
user: {}
};
componentDidMount() {
const user = this.props.uid || Fire.shared.uid;
this.unsubscribe = Fire.shared.firestore
.collection("users")
.doc(user)
.onSnapshot(doc => {
this.setState({ user: doc.data() });
});
if (!this.props.imageWidth) {
// Get the size of the web image
Image.getSize(this.props.image, (width, height) => {
this.setState({ width, height });
});
}
}
componentWillUnmount() {
this.unsubscribe();
}
render() {
const { title, address, name, imageWidth, imageHeight, image, currentLatitude, currentLongitude } = this.props;
// Reduce the name to something
const imgW = imageWidth || this.state.width;
const imgH = imageHeight || this.state.height;
const aspect = imgW / imgH || 1;
return (
<View>
<Header image={{ uri: this.state.user.avatar }} name={this.state.user.name} />
<Image
resizeMode="contain"
style={{
backgroundColor: "#D8D8D8",
width: "100%",
aspectRatio: aspect
}}
source={{ uri: image }}
/>
<Metadata
name={this.state.user.name}
address={address}
title={title}
currentLongitude={currentLongitude}
currentLatitude={currentLatitude}
/>
</View>
);
}
}
const Metadata = ({ name, address, title, currentLongitude, currentLatitude}) => (
<View style={styles.padding}>
<IconBar />
<Text style={styles.text}>{name}</Text>
<Text style={styles.subtitle}>{address}</Text>
<Text style={styles.subtitle}>{title}</Text>
<Text style={styles.subtitle}>Lat: {currentLatitude}</Text>
<Text style={styles.subtitle}>Lng: {currentLongitude}</Text>
</View>
);
const Header = ({ name, image }) => (
<View style={[styles.row, styles.padding]}>
<View style={styles.row}>
<Image style={styles.avatar} source={image} />
<Text style={styles.text}>{name}</Text>
</View>
<Icon name="ios-more" />
</View>
);
const Icon = ({ name }) => (
<Ionicons style={{ marginRight: 8 }} name={name} size={26} color="black" />
);
const IconBar = () => (
<View style={styles.row}>
<View style={styles.row}>
<Icon name="ios-heart-empty" />
<Icon name="ios-chatbubbles" />
<Icon name="ios-send"/>
</View>
<Icon name="ios-bookmark" />
</View>
);
const styles = StyleSheet.create({
text: { fontWeight: "600" },
subtitle: {
opacity: 0.8
},
row: {
flexDirection: "row",
justifyContent: "space-between",
alignItems: "center"
},
padding: {
padding
},
avatar: {
aspectRatio: 1,
backgroundColor: "#D8D8D8",
borderWidth: StyleSheet.hairlineWidth,
borderColor: "#979797",
borderRadius: profileImageSize / 2,
width: profileImageSize,
height: profileImageSize,
resizeMode: "cover",
marginRight: padding
}
});
List.js
import React from 'react';
import { FlatList } from 'react-native';
import Footer from './Footer';
import Item from './Item';
class List extends React.Component {
renderItem = ({ item }) => <Item {...item} />;
keyExtractor = item => item.key;
render() {
const { onPressFooter, ...props } = this.props;
return (
<FlatList
keyExtractor={this.keyExtractor}
ListFooterComponent={footerProps => (
<Footer {...footerProps} onPress={onPressFooter} />
)}
renderItem={this.renderItem}
{...props}
/>
);
}
}
export default List;
FeedScreen.js
import firebase from "firebase";
import React, { Component } from "react";
import { LayoutAnimation, RefreshControl } from "react-native";
import List from "../components/List";
import Fire from "./Fire";
// Set the default number of images to load for each pagination.
const PAGE_SIZE = 5;
console.disableYellowBox = true;
export default class FeedScreen extends Component {
state = {
loading: false,
data: {}
};
componentDidMount() {
// Check if we are signed in...
if (Fire.shared.uid) {
// If we are, then we can get the first 5 posts
this.makeRemoteRequest();
} else {
// If we aren't then we should just start observing changes. This will be called when the user signs in
firebase.auth().onAuthStateChanged(user => {
if (user) {
this.makeRemoteRequest();
}
});
}
}
// Append the item to our states `data` prop
addPosts = posts => {
this.setState(previousState => {
let data = {
...previousState.data,
...posts
};
return {
data,
// Sort the data by timestamp
posts: Object.values(data).sort((a, b) => a.timestamp < b.timestamp)
};
});
};
// Call our database and ask for a subset of the user posts
makeRemoteRequest = async lastKey => {
// If we are currently getting posts, then bail out..
if (this.state.loading) {
return;
}
this.setState({ loading: true });
// The data prop will be an array of posts, the cursor will be used for pagination.
const { data, cursor } = await Fire.shared.getPaged({
size: PAGE_SIZE,
start: lastKey
});
this.lastKnownKey = cursor;
// Iteratively add posts
let posts = {};
for (let child of data) {
posts[child.key] = child;
}
this.addPosts(posts);
// Finish loading, this will stop the refreshing animation.
this.setState({ loading: false });
};
// Because we want to get the most recent items, don't pass the cursor back.
// This will make the data base pull the most recent items.
_onRefresh = () => this.makeRemoteRequest();
// If we press the "Load More..." footer then get the next page of posts
onPressFooter = () => this.makeRemoteRequest(this.lastKnownKey);
render() {
// Let's make everything purrty by calling this method which animates layout changes.
LayoutAnimation.easeInEaseOut();
return (
<List
refreshControl={
<RefreshControl
refreshing={this.state.loading}
onRefresh={this._onRefresh}
/>
}
onPressFooter={this.onPressFooter}
data={this.state.posts}
/>
);
}
}

How to integrate firebase-auth to verify phone number

I have created phone number verify screen and now I want to integrate firebase-auth for verifying phone number via OTP. But I have no idea how to do that, Please help me with it.
I have tried to find tutorial and example, but those were not helpful for me.
Phone Verify Screen
import React from 'react';
import {StyleSheet, View, TextInput, TouchableOpacity, Text, KeyboardAvoidingView, BackHandler, Alert, AsyncStorage, ToastAndroid } from 'react-native';
import HandleBack from '../component/backHandler';
import * as firebase from 'firebase';
class BuyerVerify extends React.Component{
componentDidMount(){
this.getData();
};
onBack = () => {
return true;
};
getData = () => {
const getNumber = async () => {
let number = '';
try {
number = await AsyncStorage.getItem('number');
} catch (error) {
// Error retrieving data
console.log(error.message);
}
//return number;
alert(number);
}
getNumber();
};
render(){
return(
<HandleBack onBack={this.onBack}>
<View style={styles.root}>
<View style={styles.outer}>
<View style={styles.inner}>
<KeyboardAvoidingView style={styles.container}>
<TextInput style={styles.input}
placeholder="Enter OTP"
placeholderTextColor="#939eaf"
keyboardType="phone-pad"
/>
<TouchableOpacity style={styles.button1Container}>
<Text style={styles.buttonText}>
Verify Buyer
</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.button2Container} onPress={()=> this.props.navigation.navigate('Main')}>
<Text style={styles.buttonText}>
Change number
</Text>
</TouchableOpacity>
</KeyboardAvoidingView>
</View>
</View>
</View>
</HandleBack>
);
}
}
export default BuyerVerify;
I want to verify phone number via OTP using firebase.
From Firebase's PhoneAuthProvider interface:
// 'recaptcha-container' is the ID of an element in the DOM.
var applicationVerifier = new firebase.auth.RecaptchaVerifier(
'recaptcha-container');
var provider = new firebase.auth.PhoneAuthProvider();
provider.verifyPhoneNumber('+16505550101', applicationVerifier)
.then(function(verificationId) {
var verificationCode = window.prompt('Please enter the verification ' +
'code that was sent to your mobile device.');
return firebase.auth.PhoneAuthProvider.credential(verificationId,
verificationCode);
})
.then(function(phoneCredential) {
return firebase.auth().signInWithCredential(phoneCredential);
});

Resources