Open balwinders opened 6 years ago
My APP.js file code is:
import React from 'react'; import RNFirebasePhoneauth from 'react-native-firebase-phone-auth'; import { View, Text, Alert,Button } from 'react-native'; import { //... DeviceEventEmitter, } from 'react-native';
class App extends React.Component {
componentWillMount() { const firebase = require("firebase"); // To Configure react native app with cloud of Google Firebase database ! // Initialize Firebase
var config = { apiKey: "AIzaSyCafM08UNLlaRWgoMWwR8X9tTzPkf7X3N8", authDomain: "recttest-d7978.firebaseapp.com", databaseURL: "https://recttest-d7978.firebaseio.com", projectId: "recttest-d7978", storageBucket: "recttest-d7978.appspot.com", messagingSenderId: "23447215482" }; firebase.initializeApp(config); console.log(firebase);
Alert.alert("=>"+1); // firebase.initializeApp(this)
// To select data from firebase every time data has changed ! firebase.database().ref('users').on('value', (data) => { console.log(data.toJSON());
Alert.alert("=>"+2);
})
} listenToOTP3(){ RNFirebasePhoneauth.initFirebase( "recttest-d7978", "com.test", "AIzaSyCafM08UNLlaRWgoMWwR8X9tTzPkf7X3N8", "https://recttest-d7978.firebaseio.com", (resp)=>{ console.log(resp) }, (error)=>{ alert(error); console.log(error); }, ); } listenToOTP2(){ Alert.alert("=>"+2); let phoneNumber = "+91**"; RNFirebasePhoneauth.sendOTP(phoneNumber, (resp)=>{ console.log(resp) }, (error)=>{ alert(error); console.log(error); }); Alert.alert("=>"+3); } listenToOTP1(){ //Alert.alert("=>"+phoneNumber); DeviceEventEmitter.addListener('OTPStatus', (data) => {
switch(data.CODE){ case "SENT": let phoneNumber = "+91**********"; RNFirebasePhoneauth.sendOTP(phoneNumber); break; case "VERIFIED": //SMS Received & read by google play services let authData = { code : data.OTPNumber, verificationId : data.verificationId } firebase.auth().signInWithPhoneAuth( authData, (success)=>{ alert(success); console.log(error); }, (error)=>{ alert(error); console.log(error); }); break; case "ERROR": //error sending SMS break; } if(data.CODE == "ERROR") { } });
} // To Await 5 seconds to insert a new user / setTimeout(() => { firebase.database().ref('users/005').set( { name: 'Amrik Singh', age: 28 } ).then(() => { console.log('INSERTED !'); }).catch((error) => { console.log(error); }); }, 5000); / // To Update a user //firebase.database().ref('users/004').update({ // name: 'Pheng Sengvuthy' //});
// To Remove a user //firebase.database().ref('users/004').remove();
render() { return ( <View style={{ alignItems: 'center', height: '100%', justifyContent: 'center' }}> <Text style={{ fontWeight: 'bold', fontSize: 18 }}> </Text> <Button onPress={this.listenToOTP3} title="Init"> </Button> <View style={{margin: 20}}> <Button onPress={this.listenToOTP2} title="Send"> </Button> </View> <View style={{margin: 50}}> <Button onPress={this.listenToOTP1} title="Verified"> </Button> </View> </View> ) }
}
export default App;
any luck
My APP.js file code is:
import React from 'react'; import RNFirebasePhoneauth from 'react-native-firebase-phone-auth'; import { View, Text, Alert,Button } from 'react-native'; import { //... DeviceEventEmitter, } from 'react-native';
class App extends React.Component {
var config = { apiKey: "AIzaSyCafM08UNLlaRWgoMWwR8X9tTzPkf7X3N8", authDomain: "recttest-d7978.firebaseapp.com", databaseURL: "https://recttest-d7978.firebaseio.com", projectId: "recttest-d7978", storageBucket: "recttest-d7978.appspot.com", messagingSenderId: "23447215482" }; firebase.initializeApp(config); console.log(firebase);
// To select data from firebase every time data has changed ! firebase.database().ref('users').on('value', (data) => { console.log(data.toJSON());
})
} listenToOTP3(){ RNFirebasePhoneauth.initFirebase( "recttest-d7978", "com.test", "AIzaSyCafM08UNLlaRWgoMWwR8X9tTzPkf7X3N8", "https://recttest-d7978.firebaseio.com", (resp)=>{ console.log(resp) }, (error)=>{ alert(error); console.log(error); }, ); } listenToOTP2(){ Alert.alert("=>"+2); let phoneNumber = "+91**"; RNFirebasePhoneauth.sendOTP(phoneNumber, (resp)=>{ console.log(resp) }, (error)=>{ alert(error); console.log(error); }); Alert.alert("=>"+3); } listenToOTP1(){ //Alert.alert("=>"+phoneNumber); DeviceEventEmitter.addListener('OTPStatus', (data) => {
} // To Await 5 seconds to insert a new user / setTimeout(() => { firebase.database().ref('users/005').set( { name: 'Amrik Singh', age: 28 } ).then(() => { console.log('INSERTED !'); }).catch((error) => { console.log(error); }); }, 5000); / // To Update a user //firebase.database().ref('users/004').update({ // name: 'Pheng Sengvuthy' //});
// To Remove a user //firebase.database().ref('users/004').remove();
}
export default App;