Firebase Phone Authentication in React native

851 views
Skip to first unread message

Midhun Vazhoor

unread,
Apr 5, 2018, 10:13:58 AM4/5/18
to Firebase Google Group
How we can use Firebase Ohone authentication in react native mobile apps. 
When i use with this package 'react-native-firebase' ,
I got error "Phone number is invalid format" even i give phone number with country code.
Screenshot_2018-04-03-15-16-10.png.png

Ian Barber

unread,
Apr 5, 2018, 10:22:36 AM4/5/18
to Firebase Google Group
Check that you're passing the number properly to the call (e.g. try hard coding the number). If that doesn't work, we'd probably need to see some minimal code that demonstrated the problem (e.g with that hard coded number) in order to help. 

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/9e7754ac-5077-4b6e-8a7a-162a1640f8b4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Midhun Vazhoor

unread,
Apr 5, 2018, 3:49:12 PM4/5/18
to fireba...@googlegroups.com
i will prove main codes and will attach package.json and /app/build.gradle 
import firebase from 'react-native-firebase';

export default class PhoneAuthTest extends Component {
constructor(props) {
super(props);
this.unsubscribe = null;
this.state = {
user: null,
message: '',
codeInput: '',
phoneNumber: '',//'+91',
confirmResult: null,
};
}

componentDidMount() {
// debugger;
console.log('test')
this.unsubscribe = firebase.auth().onAuthStateChanged((user) => {
if (user) {
this.setState({ user: user.toJSON() });
} else {
// User has been signed out, reset the state
this.setState({
user: null,
message: '',
codeInput: '',
phoneNumber:'' ,//'+91',
confirmResult: null,
});
}
});
}


signIn = () => {
debugger;
const { phoneNumber } = this.state;
this.setState({ message: 'Sending code ...' });
console.log('signInWithPhoneNumber')
var phno=phoneNumber.toString();
console.log(phoneNumber);
console.log('ph:'+phno);
firebase.auth().verifyPhoneNumber('com.login_demo_2',phoneNumber,60) //'com.login_demo_2'
.then(confirmResult => this.setState({ confirmResult, message: 'Code has been sent!' }))
.catch(error => this.setState({ message: `Sign In With Phone Number Error: ${error.message}` }));
};

renderPhoneNumberInput() {
const { phoneNumber } = this.state;
return (
<View style={{ padding: 25 }}>
<Text>Enter phone number:</Text>
<TextInput
autoFocus
style={{ height: 40, marginTop: 15, marginBottom: 15 }}
onChangeText={value => this.setState({ phoneNumber: value })}
placeholder={'Phone number ... '}
value={phoneNumber}
/>
<Button title="Sign In" color="green" onPress={this.signIn} />
</View>
);
}



On Thu, Apr 5, 2018 at 7:51 PM, 'Ian Barber' via Firebase Google Group <fireba...@googlegroups.com> wrote:
Check that you're passing the number properly to the call (e.g. try hard coding the number). If that doesn't work, we'd probably need to see some minimal code that demonstrated the problem (e.g with that hard coded number) in order to help. 
On Thu, Apr 5, 2018 at 10:13 AM Midhun Vazhoor <kut...@gmail.com> wrote:
How we can use Firebase Ohone authentication in react native mobile apps. 
When i use with this package 'react-native-firebase' ,
I got error "Phone number is invalid format" even i give phone number with country code.

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-talk+unsubscribe@googlegroups.com.

To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/9e7754ac-5077-4b6e-8a7a-162a1640f8b4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-talk+unsubscribe@googlegroups.com.

To post to this group, send email to fireba...@googlegroups.com.
package.json
build.gradle
Reply all
Reply to author
Forward
0 new messages