Snippet:
import React, { Component } from 'react';
import { Text, TextInput, TouchableOpacity, View } from 'react-native';
import auth from '@react-native-firebase/auth';
export default class login extends Component {
constructor(props) {
super(props)
this.state = {
number:''
}
}
signInWithPhoneNumber = async() => {
const {number} = this.state
const confirmation = await auth().signInWithPhoneNumber(phoneNumber);
console.log("confirmation ==>",confirmation)
if (confirmation._auth._authResult) {
this.props.navigation.navigate("Verify")
}else {
alert("internal error")
}
}
render() {
return (
<View style={{ flex: 1 }}>
<View style={{ flex: 0.4, justifyContent: 'center', alignItems: 'center' }}>
<Text style={{ fontSize: 20 }}>Login with your number</Text>
</View>
<View style={{ flex: 0.4, justifyContent: 'center', alignItems: 'center' }}>
<TextInput
onChangeText = {(number) => this.setState({number:number})}
placeholder={"Please enter your number"}
style={{
padding: 10,
backgroundColor: "#fff",
borderBottomWidth: 1,
borderRadius: 10,
fontSize: 18,
}} />
</View>
<TouchableOpacity
onPress={this.signInWithPhoneNumber}
style={{
padding: 10,
backgroundColor: 'skyblue',
borderRadius: 10
}}><Text style={{
alignSelf: 'center',
fontWeight: 'bold',
paddingHorizontal: 10,
}}>
Send Code</Text>
</TouchableOpacity>
</View>
)
}
}
Error Log:
[Unhandled promise rejection: Error: You attempted to use a firebase module that's not installed on your Android project by calling f]rebase.app().
- node_modules\@react-native-firebase\app\lib\internal\registry\nativeModule.js:227:10 in getAppModule
...
[native code]:null in callFunctionReturnFlushedQueue
* Some other codes and explanations...