Merge branch 'v3' of https://github.com/invertase/react-native-firebase into v3
This commit is contained in:
commit
7ea92751a9
|
@ -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<AuthResult> 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);
|
||||
|
|
|
@ -382,12 +382,12 @@ public class RNFirebaseDatabase extends ReactContextBaseJavaModule {
|
|||
* @param key
|
||||
* @param path
|
||||
* @param modifiers
|
||||
* @param eventName
|
||||
* @param eventType
|
||||
* @param promise
|
||||
*/
|
||||
@ReactMethod
|
||||
public void once(String appName, String key, String path, ReadableArray modifiers, String eventName, Promise promise) {
|
||||
getInternalReferenceForApp(appName, key, path, modifiers).once(eventName, promise);
|
||||
public void once(String appName, String key, String path, ReadableArray modifiers, String eventType, Promise promise) {
|
||||
getInternalReferenceForApp(appName, key, path, modifiers).once(eventType, promise);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -400,7 +400,6 @@ public class RNFirebaseDatabase extends ReactContextBaseJavaModule {
|
|||
public void on(String appName, ReadableMap props) {
|
||||
getInternalReferenceForApp(appName, props)
|
||||
.on(
|
||||
this,
|
||||
props.getString("eventType"),
|
||||
props.getMap("registration")
|
||||
);
|
||||
|
|
|
@ -82,7 +82,8 @@ class RNFirebaseDatabaseReference {
|
|||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* Remove an event listener by key, will remove either a ValueEventListener or
|
||||
* a ChildEventListener
|
||||
*
|
||||
* @param eventRegistrationKey
|
||||
*/
|
||||
|
@ -204,28 +205,27 @@ class RNFirebaseDatabaseReference {
|
|||
/**
|
||||
* Handles a React Native JS '.on(..)' request and initializes listeners.
|
||||
*
|
||||
* @param database
|
||||
* @param registration
|
||||
*/
|
||||
void on(RNFirebaseDatabase database, String eventType, ReadableMap registration) {
|
||||
void on(String eventType, ReadableMap registration) {
|
||||
if (eventType.equals("value")) {
|
||||
addValueEventListener(registration, database);
|
||||
addValueEventListener(registration);
|
||||
} else {
|
||||
addChildEventListener(registration, eventType, database);
|
||||
addChildEventListener(registration, eventType);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a React Native JS 'once' request.
|
||||
*
|
||||
* @param eventName
|
||||
* @param eventType
|
||||
* @param promise
|
||||
*/
|
||||
void once(String eventName, Promise promise) {
|
||||
if (eventName.equals("value")) {
|
||||
void once(String eventType, Promise promise) {
|
||||
if (eventType.equals("value")) {
|
||||
addOnceValueEventListener(promise);
|
||||
} else {
|
||||
addChildOnceEventListener(eventName, promise);
|
||||
addChildOnceEventListener(eventType, promise);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -235,9 +235,8 @@ class RNFirebaseDatabaseReference {
|
|||
*
|
||||
* @param registration
|
||||
* @param eventType
|
||||
* @param database
|
||||
*/
|
||||
private void addChildEventListener(final ReadableMap registration, final String eventType, final RNFirebaseDatabase database) {
|
||||
private void addChildEventListener(final ReadableMap registration, final String eventType) {
|
||||
final String eventRegistrationKey = registration.getString("eventRegistrationKey");
|
||||
final String registrationCancellationKey = registration.getString("registrationCancellationKey");
|
||||
|
||||
|
@ -286,11 +285,9 @@ class RNFirebaseDatabaseReference {
|
|||
* Add a native .on('value',.. ) event listener.
|
||||
*
|
||||
* @param registration
|
||||
* @param database
|
||||
*/
|
||||
private void addValueEventListener(final ReadableMap registration, final RNFirebaseDatabase database) {
|
||||
private void addValueEventListener(final ReadableMap registration) {
|
||||
final String eventRegistrationKey = registration.getString("eventRegistrationKey");
|
||||
final String registrationCancellationKey = registration.getString("registrationCancellationKey");
|
||||
|
||||
if (!hasEventListener(eventRegistrationKey)) {
|
||||
ValueEventListener valueEventListener = new ValueEventListener() {
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -1,91 +1,91 @@
|
|||
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 firebase from './firebase';
|
||||
import DatabaseContents from './tests/support/DatabaseContents';
|
||||
import fb from './firebase';
|
||||
const firebase = fb.native;
|
||||
|
||||
const successImageUri = 'https://cdn.pixabay.com/photo/2015/06/09/16/12/icon-803718_1280.png';
|
||||
|
||||
export default class HomeScreen extends Component {
|
||||
|
||||
export default class PhoneAuthTest extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
timeTaken: '',
|
||||
user: null,
|
||||
message: '',
|
||||
codeInput: '',
|
||||
phoneNumber: '+44',
|
||||
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 ...' });
|
||||
|
||||
const callbackA = sinon.spy();
|
||||
const callbackB = sinon.spy();
|
||||
firebase.auth()
|
||||
.signInWithPhoneNumber(phoneNumber)
|
||||
.onCodeSent(confirmResult => this.setState({ confirmResult, message: 'Code has been sent!' }))
|
||||
.then(user => this.setState({ user: user.toJSON() }))
|
||||
.catch(console.error);
|
||||
};
|
||||
|
||||
// Test
|
||||
confirmCode = () => {
|
||||
const { codeInput, confirmResult } = this.state;
|
||||
|
||||
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 (
|
||||
<View style={{ marginTop: 15, backgroundColor: '#000' }}>
|
||||
<Button title="Run Test" onPress={this.clickMe} />
|
||||
<Text style={{ color: '#fff' }}>{this.state.timeTaken || ''}</Text>
|
||||
<View style={{ flex: 1 }}>
|
||||
{!user && !confirmResult ? (
|
||||
<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>
|
||||
) : null}
|
||||
{message.length ? (
|
||||
<Text style={{ padding: 5, backgroundColor: '#000', color: '#fff' }}>{message}</Text>) : null}
|
||||
{!user && confirmResult ? (
|
||||
<View style={{ marginTop: 25, padding: 25 }}>
|
||||
<Text>Enter verification code below:</Text>
|
||||
<TextInput
|
||||
autoFocus
|
||||
style={{ height: 40, marginTop: 15, marginBottom: 15 }}
|
||||
onChangeText={value => this.setState({ codeInput: value })}
|
||||
placeholder={'Code ... '}
|
||||
value={codeInput}
|
||||
/>
|
||||
<Button title="Confirm Code" color="#841584" onPress={this.confirmCode} />
|
||||
</View>
|
||||
) : null}
|
||||
{ user ? (
|
||||
<View
|
||||
style={{
|
||||
padding: 15,
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center',
|
||||
backgroundColor: '#77dd77',
|
||||
flex: 1,
|
||||
}}
|
||||
>
|
||||
<Image source={{ uri: successImageUri }} style={{ width: 100, height: 100, marginBottom: 25 }} />
|
||||
<Text style={{ fontSize: 25 }}>Signed In!</Text>
|
||||
<Text>{JSON.stringify(user)}</Text>
|
||||
</View>
|
||||
) : null}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue