diff --git a/android/src/main/java/io/invertase/firebase/auth/RNFirebaseAuth.java b/android/src/main/java/io/invertase/firebase/auth/RNFirebaseAuth.java index 58803e80..6061ab9f 100644 --- a/android/src/main/java/io/invertase/firebase/auth/RNFirebaseAuth.java +++ b/android/src/main/java/io/invertase/firebase/auth/RNFirebaseAuth.java @@ -581,7 +581,7 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule { // Reset the verification Id mVerificationId = null; - PhoneAuthProvider.getInstance(firebaseAuth).verifyPhoneNumber(phoneNumber, 120, TimeUnit.SECONDS, + PhoneAuthProvider.getInstance(firebaseAuth).verifyPhoneNumber(phoneNumber, 60, TimeUnit.SECONDS, mReactContext.getCurrentActivity(), new PhoneAuthProvider.OnVerificationStateChangedCallbacks() { @Override public void onVerificationCompleted(final PhoneAuthCredential phoneAuthCredential) { @@ -596,7 +596,7 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule { event.putMap("user", user); event.putString("type", "user"); event.putString("appName", appName); - event.putString("appName", phoneAuthCredential.getSmsCode()); + event.putString("smsCode", phoneAuthCredential.getSmsCode()); event.putString("phoneAuthRequestKey", phoneAuthRequestKey); Utils.sendEvent(mReactContext, "phone_auth_event", event); } @@ -618,6 +618,7 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule { @Override public void onVerificationFailed(FirebaseException e) { + Log.d(TAG, "signInWithPhoneNumber:verification:failed"); WritableMap event = Arguments.createMap(); WritableMap error = getJSError(e); event.putMap("error", error); @@ -650,6 +651,9 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule { FirebaseApp firebaseApp = FirebaseApp.getInstance(appName); FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(firebaseApp); + // Log.d(TAG, "_confirmVerificationCode:verificationId: " + verificationId); + // Log.d(TAG, "_confirmVerificationCode:verificationCode: " + verificationCode); + PhoneAuthCredential credential = PhoneAuthProvider.getCredential(verificationId, verificationCode); firebaseAuth.signInWithCredential(credential) @@ -657,7 +661,7 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule { @Override public void onComplete(@NonNull Task task) { if (task.isSuccessful()) { - Log.d(TAG, "signInWithCredential:onComplete:success"); + Log.d(TAG, "_confirmVerificationCode:signInWithCredential:onComplete:success"); WritableMap event = Arguments.createMap(); WritableMap user = firebaseUserToMap(task.getResult().getUser()); event.putMap("user", user); @@ -668,7 +672,7 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule { promiseWithUser(task.getResult().getUser(), promise); } else { Exception exception = task.getException(); - Log.e(TAG, "signInWithCredential:onComplete:failure", exception); + Log.e(TAG, "_confirmVerificationCode:signInWithCredential:onComplete:failure", exception); WritableMap event = Arguments.createMap(); WritableMap error = getJSError(exception); event.putMap("error", error); diff --git a/tests/android/app/build.gradle b/tests/android/app/build.gradle index 99eb14be..01164748 100644 --- a/tests/android/app/build.gradle +++ b/tests/android/app/build.gradle @@ -5,9 +5,9 @@ import com.android.build.OutputFile project.ext.react = [ // whether to bundle JS and assets in staging mode - bundleInDebug : true, - jsBundleDirDebug: "$buildDir/intermediates/assets/debug", - nodeExecutableAndArgs : ["/usr/local/bin/node"] + bundleInDebug : false, + jsBundleDirDebug : "$buildDir/intermediates/assets/debug", + nodeExecutableAndArgs: ["/usr/local/bin/node"] ] apply from: "../../node_modules/react-native/react.gradle" diff --git a/tests/src/bench.js b/tests/src/bench.js index 87085425..fbfdd301 100644 --- a/tests/src/bench.js +++ b/tests/src/bench.js @@ -1,92 +1,175 @@ import React, { Component } from 'react'; -import { View, Button, Text } from 'react-native'; -import sinon from 'sinon'; -import 'should-sinon'; -import Promise from 'bluebird'; +import { View, Button, Text, TextInput, Image } from 'react-native'; +import fb from './firebase'; +const firebase = fb.native; -import firebase from './firebase'; -import DatabaseContents from './tests/support/DatabaseContents'; - - -export default class HomeScreen extends Component { +const successImageUri = 'https://cdn.pixabay.com/photo/2015/06/09/16/12/icon-803718_1280.png'; +export default class PhoneAuthTest extends Component { constructor(props) { super(props); this.state = { - timeTaken: '', + user: null, + message: '', + codeInput: '', + phoneNumber: '+447445255177', + confirmResult: null, }; } - clickMe = () => { - this.setState({ timeTaken: 'Running...' }); - let start = null; - Promise.all([ - firebase.native.database().ref('tests/types').set(DatabaseContents.DEFAULT), - firebase.native.database().ref('tests/priority').setWithPriority({ - foo: 'bar', - }, 666), - firebase.native.database().ref('tests/query').set(DatabaseContents.QUERY), - ]).then(() => { - start = Date.now(); - return Promise.each(Object.keys(DatabaseContents.DEFAULT), async (dataRef) => { - // Setup - const ref = firebase.native.database().ref(`tests/types/${dataRef}`); - const currentDataValue = DatabaseContents.DEFAULT[dataRef]; + signIn = () => { + const { phoneNumber } = this.state; + this.setState({ message: 'Sending code ...' }); + firebase.auth() + .signInWithPhoneNumber(phoneNumber) + .onCodeSent(confirmResult => this.setState({ confirmResult, message: 'Code has been sent!' })) + .then(user => this.setState({ user: user.toJSON() })) + .catch(console.error); + }; - const callbackA = sinon.spy(); - const callbackB = sinon.spy(); + confirmCode = () => { + const { codeInput, confirmResult } = this.state; - // Test - - await new Promise((resolve) => { - ref.on('value', (snapshot) => { - callbackA(snapshot.val()); - resolve(); - }); - }); - - await new Promise((resolve) => { - ref.on('value', (snapshot) => { - callbackB(snapshot.val()); - resolve(); - }); - }); - - callbackA.should.be.calledWith(currentDataValue); - callbackA.should.be.calledOnce(); - - callbackB.should.be.calledWith(currentDataValue); - callbackB.should.be.calledOnce(); - - const newDataValue = DatabaseContents.NEW[dataRef]; - await ref.set(newDataValue); - - await new Promise((resolve) => { - setTimeout(() => resolve(), 5); - }); - - callbackA.should.be.calledWith(newDataValue); - callbackB.should.be.calledWith(newDataValue); - - callbackA.should.be.calledTwice(); - callbackB.should.be.calledTwice(); - - // Tear down - - ref.off('value'); - return Promise.resolve(); - }); - }).then(() => { - this.setState({ timeTaken: `Took ${Date.now() - start}` }); - }).catch(console.error); + if (confirmResult && codeInput.length) { + confirmResult.confirm(codeInput) + .then(() => this.setState({ message: 'Code Confirmed!' })) + .catch(error => this.setState({ message: `Code Confirm Error: ${error.message}` })); + } }; render() { + const { message, user, codeInput, confirmResult, phoneNumber } = this.state; return ( - -