Merge branch 'v3.0.x'
# Conflicts: # docs/modules/authentication.md # package.json
This commit is contained in:
commit
3d57cdc634
|
@ -1059,13 +1059,13 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule {
|
||||||
*/
|
*/
|
||||||
private AuthCredential getCredentialForProvider(String provider, String authToken, String authSecret) {
|
private AuthCredential getCredentialForProvider(String provider, String authToken, String authSecret) {
|
||||||
switch (provider) {
|
switch (provider) {
|
||||||
case "facebook":
|
case "facebook.com":
|
||||||
return FacebookAuthProvider.getCredential(authToken);
|
return FacebookAuthProvider.getCredential(authToken);
|
||||||
case "google":
|
case "google.com":
|
||||||
return GoogleAuthProvider.getCredential(authToken, authSecret);
|
return GoogleAuthProvider.getCredential(authToken, authSecret);
|
||||||
case "twitter":
|
case "twitter.com":
|
||||||
return TwitterAuthProvider.getCredential(authToken, authSecret);
|
return TwitterAuthProvider.getCredential(authToken, authSecret);
|
||||||
case "github":
|
case "github.com":
|
||||||
return GithubAuthProvider.getCredential(authToken);
|
return GithubAuthProvider.getCredential(authToken);
|
||||||
case "phone":
|
case "phone":
|
||||||
return PhoneAuthProvider.getCredential(authToken, authSecret);
|
return PhoneAuthProvider.getCredential(authToken, authSecret);
|
||||||
|
|
|
@ -25,12 +25,14 @@ import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
|
||||||
import io.invertase.firebase.Utils;
|
import io.invertase.firebase.Utils;
|
||||||
|
|
||||||
public class FirestoreSerialize {
|
public class FirestoreSerialize {
|
||||||
private static final String TAG = "FirestoreSerialize";
|
private static final String TAG = "FirestoreSerialize";
|
||||||
private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
|
private static final DateFormat READ_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
|
||||||
|
private static final DateFormat WRITE_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
|
||||||
private static final String KEY_CHANGES = "changes";
|
private static final String KEY_CHANGES = "changes";
|
||||||
private static final String KEY_DATA = "data";
|
private static final String KEY_DATA = "data";
|
||||||
private static final String KEY_DOC_CHANGE_DOCUMENT = "document";
|
private static final String KEY_DOC_CHANGE_DOCUMENT = "document";
|
||||||
|
@ -41,6 +43,12 @@ public class FirestoreSerialize {
|
||||||
private static final String KEY_METADATA = "metadata";
|
private static final String KEY_METADATA = "metadata";
|
||||||
private static final String KEY_PATH = "path";
|
private static final String KEY_PATH = "path";
|
||||||
|
|
||||||
|
static {
|
||||||
|
// Javascript Date.toISOString is always formatted to UTC
|
||||||
|
// We set the read TimeZone to UTC to account for this
|
||||||
|
READ_DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a DocumentSnapshot instance into a React Native WritableMap
|
* Convert a DocumentSnapshot instance into a React Native WritableMap
|
||||||
*
|
*
|
||||||
|
@ -212,7 +220,7 @@ public class FirestoreSerialize {
|
||||||
typeMap.putMap("value", geoPoint);
|
typeMap.putMap("value", geoPoint);
|
||||||
} else if (value instanceof Date) {
|
} else if (value instanceof Date) {
|
||||||
typeMap.putString("type", "date");
|
typeMap.putString("type", "date");
|
||||||
typeMap.putString("value", DATE_FORMAT.format((Date) value));
|
typeMap.putString("value", WRITE_DATE_FORMAT.format((Date) value));
|
||||||
} else {
|
} else {
|
||||||
// TODO: Changed to log an error rather than crash - is this correct?
|
// TODO: Changed to log an error rather than crash - is this correct?
|
||||||
Log.e(TAG, "buildTypeMap: Cannot convert object of type " + value.getClass());
|
Log.e(TAG, "buildTypeMap: Cannot convert object of type " + value.getClass());
|
||||||
|
@ -269,7 +277,7 @@ public class FirestoreSerialize {
|
||||||
} else if ("date".equals(type)) {
|
} else if ("date".equals(type)) {
|
||||||
try {
|
try {
|
||||||
String date = typeMap.getString("value");
|
String date = typeMap.getString("value");
|
||||||
return DATE_FORMAT.parse(date);
|
return READ_DATE_FORMAT.parse(date);
|
||||||
} catch (ParseException exception) {
|
} catch (ParseException exception) {
|
||||||
Log.e(TAG, "parseTypeMap", exception);
|
Log.e(TAG, "parseTypeMap", exception);
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -111,18 +111,6 @@ public class RNFirebaseFirestore extends ReactContextBaseJavaModule {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ReactMethod
|
|
||||||
public void documentCollections(String appName, String path, final Promise promise) {
|
|
||||||
RNFirebaseFirestoreDocumentReference ref = getDocumentForAppPath(appName, path);
|
|
||||||
ref.collections(promise);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ReactMethod
|
|
||||||
public void documentCreate(String appName, String path, ReadableMap data, final Promise promise) {
|
|
||||||
RNFirebaseFirestoreDocumentReference ref = getDocumentForAppPath(appName, path);
|
|
||||||
ref.create(data, promise);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ReactMethod
|
@ReactMethod
|
||||||
public void documentDelete(String appName, String path, final Promise promise) {
|
public void documentDelete(String appName, String path, final Promise promise) {
|
||||||
RNFirebaseFirestoreDocumentReference ref = getDocumentForAppPath(appName, path);
|
RNFirebaseFirestoreDocumentReference ref = getDocumentForAppPath(appName, path);
|
||||||
|
|
|
@ -40,14 +40,6 @@ public class RNFirebaseFirestoreDocumentReference {
|
||||||
this.ref = RNFirebaseFirestore.getFirestoreForApp(appName).document(path);
|
this.ref = RNFirebaseFirestore.getFirestoreForApp(appName).document(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void collections(Promise promise) {
|
|
||||||
// Not supported on Android
|
|
||||||
}
|
|
||||||
|
|
||||||
public void create(ReadableMap data, Promise promise) {
|
|
||||||
// Not supported on Android out of the box
|
|
||||||
}
|
|
||||||
|
|
||||||
public void delete(final Promise promise) {
|
public void delete(final Promise promise) {
|
||||||
this.ref.delete().addOnCompleteListener(new OnCompleteListener<Void>() {
|
this.ref.delete().addOnCompleteListener(new OnCompleteListener<Void>() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -794,7 +794,15 @@ RCT_EXPORT_METHOD(unlink:
|
||||||
if (error) {
|
if (error) {
|
||||||
[self promiseRejectAuthException:reject error:error];
|
[self promiseRejectAuthException:reject error:error];
|
||||||
} else {
|
} else {
|
||||||
[self promiseWithUser:resolve rejecter:reject user:_user];
|
// This is here to protect against bugs in the iOS SDK which don't
|
||||||
|
// correctly refresh the user object when unlinking certain accounts
|
||||||
|
[user reloadWithCompletion:^(NSError * _Nullable error) {
|
||||||
|
if (error) {
|
||||||
|
[self promiseRejectAuthException:reject error:error];
|
||||||
|
} else {
|
||||||
|
[self promiseWithUser:resolve rejecter:reject user:user];
|
||||||
|
}
|
||||||
|
}];
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
} else {
|
} else {
|
||||||
|
@ -889,15 +897,15 @@ RCT_EXPORT_METHOD(fetchProvidersForEmail:
|
||||||
- (FIRAuthCredential *)getCredentialForProvider:(NSString *)provider token:(NSString *)authToken secret:(NSString *)authTokenSecret {
|
- (FIRAuthCredential *)getCredentialForProvider:(NSString *)provider token:(NSString *)authToken secret:(NSString *)authTokenSecret {
|
||||||
FIRAuthCredential *credential;
|
FIRAuthCredential *credential;
|
||||||
|
|
||||||
if ([provider compare:@"twitter" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
|
if ([provider compare:@"twitter.com" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
|
||||||
credential = [FIRTwitterAuthProvider credentialWithToken:authToken secret:authTokenSecret];
|
credential = [FIRTwitterAuthProvider credentialWithToken:authToken secret:authTokenSecret];
|
||||||
} else if ([provider compare:@"facebook" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
|
} else if ([provider compare:@"facebook.com" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
|
||||||
credential = [FIRFacebookAuthProvider credentialWithAccessToken:authToken];
|
credential = [FIRFacebookAuthProvider credentialWithAccessToken:authToken];
|
||||||
} else if ([provider compare:@"google" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
|
} else if ([provider compare:@"google.com" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
|
||||||
credential = [FIRGoogleAuthProvider credentialWithIDToken:authToken accessToken:authTokenSecret];
|
credential = [FIRGoogleAuthProvider credentialWithIDToken:authToken accessToken:authTokenSecret];
|
||||||
} else if ([provider compare:@"password" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
|
} else if ([provider compare:@"password" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
|
||||||
credential = [FIREmailAuthProvider credentialWithEmail:authToken password:authTokenSecret];
|
credential = [FIREmailAuthProvider credentialWithEmail:authToken password:authTokenSecret];
|
||||||
} else if ([provider compare:@"github" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
|
} else if ([provider compare:@"github.com" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
|
||||||
credential = [FIRGitHubAuthProvider credentialWithToken:authToken];
|
credential = [FIRGitHubAuthProvider credentialWithToken:authToken];
|
||||||
} else if ([provider compare:@"phone" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
|
} else if ([provider compare:@"phone" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
|
||||||
credential = [[FIRPhoneAuthProvider provider] credentialWithVerificationID:authToken verificationCode:authTokenSecret];
|
credential = [[FIRPhoneAuthProvider provider] credentialWithVerificationID:authToken verificationCode:authTokenSecret];
|
||||||
|
|
|
@ -246,10 +246,12 @@ RCT_EXPORT_METHOD(on:(NSString *) appName
|
||||||
RCT_EXPORT_METHOD(off:(NSString *) key
|
RCT_EXPORT_METHOD(off:(NSString *) key
|
||||||
eventRegistrationKey:(NSString *) eventRegistrationKey) {
|
eventRegistrationKey:(NSString *) eventRegistrationKey) {
|
||||||
RNFirebaseDatabaseReference *ref = _dbReferences[key];
|
RNFirebaseDatabaseReference *ref = _dbReferences[key];
|
||||||
[ref removeEventListener:eventRegistrationKey];
|
if (ref) {
|
||||||
|
[ref removeEventListener:eventRegistrationKey];
|
||||||
|
|
||||||
if (![ref hasListeners]) {
|
if (![ref hasListeners]) {
|
||||||
[_dbReferences removeObjectForKey:key];
|
[_dbReferences removeObjectForKey:key];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -85,21 +85,6 @@ RCT_EXPORT_METHOD(documentBatch:(NSString *) appName
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(documentCollections:(NSString *) appName
|
|
||||||
path:(NSString *) path
|
|
||||||
resolver:(RCTPromiseResolveBlock) resolve
|
|
||||||
rejecter:(RCTPromiseRejectBlock) reject) {
|
|
||||||
[[self getDocumentForAppPath:appName path:path] get:resolve rejecter:reject];
|
|
||||||
}
|
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(documentCreate:(NSString *) appName
|
|
||||||
path:(NSString *) path
|
|
||||||
data:(NSDictionary *) data
|
|
||||||
resolver:(RCTPromiseResolveBlock) resolve
|
|
||||||
rejecter:(RCTPromiseRejectBlock) reject) {
|
|
||||||
[[self getDocumentForAppPath:appName path:path] create:data resolver:resolve rejecter:reject];
|
|
||||||
}
|
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(documentDelete:(NSString *) appName
|
RCT_EXPORT_METHOD(documentDelete:(NSString *) appName
|
||||||
path:(NSString *) path
|
path:(NSString *) path
|
||||||
resolver:(RCTPromiseResolveBlock) resolve
|
resolver:(RCTPromiseResolveBlock) resolve
|
||||||
|
|
|
@ -17,8 +17,6 @@
|
||||||
@property FIRDocumentReference *ref;
|
@property FIRDocumentReference *ref;
|
||||||
|
|
||||||
- (id)initWithPath:(RCTEventEmitter *)emitter app:(NSString *)app path:(NSString *)path;
|
- (id)initWithPath:(RCTEventEmitter *)emitter app:(NSString *)app path:(NSString *)path;
|
||||||
- (void)collections:(RCTPromiseResolveBlock) resolve rejecter:(RCTPromiseRejectBlock) reject;
|
|
||||||
- (void)create:(NSDictionary *)data resolver:(RCTPromiseResolveBlock) resolve rejecter:(RCTPromiseRejectBlock) reject;
|
|
||||||
- (void)delete:(RCTPromiseResolveBlock) resolve rejecter:(RCTPromiseRejectBlock) reject;
|
- (void)delete:(RCTPromiseResolveBlock) resolve rejecter:(RCTPromiseRejectBlock) reject;
|
||||||
- (void)get:(RCTPromiseResolveBlock) resolve rejecter:(RCTPromiseRejectBlock) reject;
|
- (void)get:(RCTPromiseResolveBlock) resolve rejecter:(RCTPromiseRejectBlock) reject;
|
||||||
+ (void)offSnapshot:(NSString *)listenerId;
|
+ (void)offSnapshot:(NSString *)listenerId;
|
||||||
|
|
|
@ -23,17 +23,6 @@ static NSMutableDictionary *_listeners;
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)collections:(RCTPromiseResolveBlock) resolve
|
|
||||||
rejecter:(RCTPromiseRejectBlock) reject {
|
|
||||||
// Not supported on iOS
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)create:(NSDictionary *) data
|
|
||||||
resolver:(RCTPromiseResolveBlock) resolve
|
|
||||||
rejecter:(RCTPromiseRejectBlock) reject {
|
|
||||||
// Not supported on iOS out of the box
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)delete:(RCTPromiseResolveBlock) resolve
|
- (void)delete:(RCTPromiseResolveBlock) resolve
|
||||||
rejecter:(RCTPromiseRejectBlock) reject {
|
rejecter:(RCTPromiseRejectBlock) reject {
|
||||||
[_ref deleteDocumentWithCompletion:^(NSError * _Nullable error) {
|
[_ref deleteDocumentWithCompletion:^(NSError * _Nullable error) {
|
||||||
|
@ -176,7 +165,7 @@ static NSMutableDictionary *_listeners;
|
||||||
NSDictionary *typeMap = [RNFirebaseFirestoreDocumentReference buildTypeMap:obj];
|
NSDictionary *typeMap = [RNFirebaseFirestoreDocumentReference buildTypeMap:obj];
|
||||||
map[key] = typeMap;
|
map[key] = typeMap;
|
||||||
}];
|
}];
|
||||||
|
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,7 +175,7 @@ static NSMutableDictionary *_listeners;
|
||||||
NSDictionary *typeMap = [RNFirebaseFirestoreDocumentReference buildTypeMap:obj];
|
NSDictionary *typeMap = [RNFirebaseFirestoreDocumentReference buildTypeMap:obj];
|
||||||
[array addObject:typeMap];
|
[array addObject:typeMap];
|
||||||
}];
|
}];
|
||||||
|
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,7 +220,7 @@ static NSMutableDictionary *_listeners;
|
||||||
// TODO: Log an error
|
// TODO: Log an error
|
||||||
typeMap[@"type"] = @"null";
|
typeMap[@"type"] = @"null";
|
||||||
}
|
}
|
||||||
|
|
||||||
return typeMap;
|
return typeMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
const providerId = 'facebook';
|
const providerId = 'facebook.com';
|
||||||
|
|
||||||
export default class FacebookAuthProvider {
|
export default class FacebookAuthProvider {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
const providerId = 'github';
|
const providerId = 'github.com';
|
||||||
|
|
||||||
export default class GithubAuthProvider {
|
export default class GithubAuthProvider {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
const providerId = 'google';
|
const providerId = 'google.com';
|
||||||
|
|
||||||
export default class GoogleAuthProvider {
|
export default class GoogleAuthProvider {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
const providerId = 'twitter';
|
const providerId = 'twitter.com';
|
||||||
|
|
||||||
export default class TwitterAuthProvider {
|
export default class TwitterAuthProvider {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|
|
@ -74,7 +74,6 @@ export default class Reference extends ReferenceBase {
|
||||||
this._refListeners = {};
|
this._refListeners = {};
|
||||||
this._database = database;
|
this._database = database;
|
||||||
this._query = new Query(this, path, existingModifiers);
|
this._query = new Query(this, path, existingModifiers);
|
||||||
this.log = this._database.log;
|
|
||||||
this.log.debug('Created new Reference', this._getRefKey());
|
this.log.debug('Created new Reference', this._getRefKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "react-native-firebase",
|
"name": "react-native-firebase",
|
||||||
"version": "3.0.3",
|
"version": "3.0.4",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
@ -426,13 +426,15 @@ function documentReferenceTests({ describe, it, context, firebase }) {
|
||||||
|
|
||||||
context('types', () => {
|
context('types', () => {
|
||||||
it('should handle Date field', async () => {
|
it('should handle Date field', async () => {
|
||||||
|
const date = new Date();
|
||||||
const docRef = firebase.native.firestore().doc('document-tests/reference');
|
const docRef = firebase.native.firestore().doc('document-tests/reference');
|
||||||
await docRef.set({
|
await docRef.set({
|
||||||
field: new Date(),
|
field: date,
|
||||||
});
|
});
|
||||||
|
|
||||||
const doc = await docRef.get();
|
const doc = await docRef.get();
|
||||||
doc.data().field.should.be.instanceof(Date);
|
doc.data().field.should.be.instanceof(Date);
|
||||||
|
should.equal(doc.data().field.toISOString(), date.toISOString());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue