Merge remote-tracking branch 'inter/master'

This commit is contained in:
ugiacoman 2017-07-05 10:13:17 -04:00
commit 591b0cc151
6 changed files with 245 additions and 87 deletions

View File

@ -23,6 +23,7 @@ import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener; import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task; import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.ActionCodeResult;
import com.google.firebase.auth.AuthCredential; import com.google.firebase.auth.AuthCredential;
import com.google.firebase.auth.AuthResult; import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuthInvalidCredentialsException; import com.google.firebase.auth.FirebaseAuthInvalidCredentialsException;
@ -503,28 +504,90 @@ public class RNFirebaseAuth extends ReactContextBaseJavaModule {
} }
/** /**
* confirmPasswordReset
* *
* @param code * @param code
* @param newPassword * @param newPassword
* @param promise * @param promise
*/ */
@ReactMethod @ReactMethod
public void confirmPasswordReset(final String code, final String newPassword, final Promise promise) { public void confirmPasswordReset(String code, String newPassword, final Promise promise) {
Log.d(TAG, "confirmPasswordReset"); Log.d(TAG, "confirmPasswordReset");
mAuth.confirmPasswordReset(code, newPassword) mAuth.confirmPasswordReset(code, newPassword)
.addOnCompleteListener(new OnCompleteListener<Void>() { .addOnCompleteListener(new OnCompleteListener<Void>() {
@Override @Override
public void onComplete(@NonNull Task<Void> task) { public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) { if (task.isSuccessful()) {
Log.d(TAG, "confirmPasswordReset:onComplete:success"); Log.d(TAG, "confirmPasswordReset:onComplete:success");
promiseNoUser(promise, false); promiseNoUser(promise, false);
} else { } else {
Exception exception = task.getException(); Exception exception = task.getException();
Log.e(TAG, "confirmPasswordReset:onComplete:failure", exception); Log.e(TAG, "confirmPasswordReset:onComplete:failure", exception);
promiseRejectAuthException(promise, exception); promiseRejectAuthException(promise, exception);
}
} }
}); }
});
}
/**
* applyActionCode
*
* @param code
* @param promise
*/
@ReactMethod
public void applyActionCode(String code, final Promise promise) {
Log.d(TAG, "applyActionCode");
mAuth.applyActionCode(code).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Log.d(TAG, "applyActionCode:onComplete:success");
promiseNoUser(promise, false);
} else {
Exception exception = task.getException();
Log.e(TAG, "applyActionCode:onComplete:failure", exception);
promiseRejectAuthException(promise, exception);
}
}
});
}
/**
* @param code
* @param promise
*/
@ReactMethod
public void checkActionCode(String code, final Promise promise) {
Log.d(TAG, "checkActionCode");
mAuth.checkActionCode(code).addOnCompleteListener(new OnCompleteListener<ActionCodeResult>() {
@Override
public void onComplete(@NonNull Task<ActionCodeResult> task) {
if (task.isSuccessful()) {
Log.d(TAG, "checkActionCode:onComplete:success");
ActionCodeResult result = task.getResult();
WritableMap writableMap = Arguments.createMap();
WritableMap dataMap = Arguments.createMap();
dataMap.putString("email", result.getData(ActionCodeResult.EMAIL));
dataMap.putString("fromEmail", result.getData(ActionCodeResult.FROM_EMAIL));
writableMap.putMap("data", dataMap);
// TODO figure out if these are required - web sdk only returns the 'email' and nothing else
// writableMap.putString("error", result.getData(ActionCodeResult.ERROR));
// writableMap.putString("verifyEmail", result.getData(ActionCodeResult.VERIFY_EMAIL));
// writableMap.putString("recoverEmail", result.getData(ActionCodeResult.RECOVER_EMAIL));
// writableMap.putString("passwordReset", result.getData(ActionCodeResult.PASSWORD_RESET));
promise.resolve(writableMap);
} else {
Exception exception = task.getException();
Log.e(TAG, "checkActionCode:onComplete:failure", exception);
promiseRejectAuthException(promise, exception);
}
}
});
} }
/** /**
@ -670,28 +733,28 @@ public class RNFirebaseAuth extends ReactContextBaseJavaModule {
Log.d(TAG, "fetchProvidersForEmail"); Log.d(TAG, "fetchProvidersForEmail");
mAuth.fetchProvidersForEmail(email) mAuth.fetchProvidersForEmail(email)
.addOnCompleteListener(new OnCompleteListener<ProviderQueryResult>() { .addOnCompleteListener(new OnCompleteListener<ProviderQueryResult>() {
@Override @Override
public void onComplete(@NonNull Task<ProviderQueryResult> task) { public void onComplete(@NonNull Task<ProviderQueryResult> task) {
if (task.isSuccessful()) { if (task.isSuccessful()) {
Log.d(TAG, "fetchProvidersForEmail:onComplete:success"); Log.d(TAG, "fetchProvidersForEmail:onComplete:success");
List<String> providers = task.getResult().getProviders(); List<String> providers = task.getResult().getProviders();
WritableArray array = Arguments.createArray(); WritableArray array = Arguments.createArray();
if (providers != null) { if (providers != null) {
for(String provider : providers) { for (String provider : providers) {
array.pushString(provider); array.pushString(provider);
}
} }
promise.resolve(array);
} else {
Exception exception = task.getException();
Log.d(TAG, "fetchProvidersForEmail:onComplete:failure", exception);
promiseRejectAuthException(promise, exception);
} }
promise.resolve(array);
} else {
Exception exception = task.getException();
Log.d(TAG, "fetchProvidersForEmail:onComplete:failure", exception);
promiseRejectAuthException(promise, exception);
} }
}); }
});
} }
/* ------------------ /* ------------------
@ -811,6 +874,7 @@ public class RNFirebaseAuth extends ReactContextBaseJavaModule {
/** /**
* Converts a List of UserInfo instances into the correct format to match the web sdk * Converts a List of UserInfo instances into the correct format to match the web sdk
*
* @param providerData List<UserInfo> user.getProviderData() * @param providerData List<UserInfo> user.getProviderData()
* @return WritableArray array * @return WritableArray array
*/ */

View File

@ -17,7 +17,7 @@
loadSidebar: true, loadSidebar: true,
search: 'auto', search: 'auto',
themeColor: '#f5820b', themeColor: '#f5820b',
subMaxLevel: 2, subMaxLevel: 3,
maxLevel: 4, maxLevel: 4,
ga: 'UA-98196653-1', ga: 'UA-98196653-1',
plugins: [ plugins: [

122
index.d.ts vendored
View File

@ -7,10 +7,15 @@ declare module "react-native-firebase" {
export default class FireBase { export default class FireBase {
constructor(config?: RNFirebase.configurationOptions) constructor(config?: RNFirebase.configurationOptions)
log: any log: any
analytics(): RNFirebase.Analytics; analytics(): RNFirebase.Analytics;
auth(): RNFirebase.auth.Auth; auth(): RNFirebase.auth.Auth;
on(type: string, handler: (msg: any) => void): any; on(type: string, handler: (msg: any) => void): any;
/** mimics firebase Web SDK */ /** mimics firebase Web SDK */
database: { database: {
(): RNFirebase.database.Database (): RNFirebase.database.Database
@ -18,10 +23,12 @@ declare module "react-native-firebase" {
TIMESTAMP: number TIMESTAMP: number
} }
} }
/**RNFirebase mimics the Web Firebase SDK Storage, /**RNFirebase mimics the Web Firebase SDK Storage,
* whilst providing some iOS and Android specific functionality. * whilst providing some iOS and Android specific functionality.
*/ */
storage(): RNFirebase.storage.Storage; storage(): RNFirebase.storage.Storage;
/** /**
* Firebase Cloud Messaging (FCM) allows you to send push messages at no cost to both Android & iOS platforms. * Firebase Cloud Messaging (FCM) allows you to send push messages at no cost to both Android & iOS platforms.
* Assuming the installation instructions have been followed, FCM is ready to go. * Assuming the installation instructions have been followed, FCM is ready to go.
@ -29,6 +36,7 @@ declare module "react-native-firebase" {
* the following methods within react-native-firebase have been created to handle FCM in the React Native environment. * the following methods within react-native-firebase have been created to handle FCM in the React Native environment.
*/ */
messaging(): RNFirebase.messaging.Messaging; messaging(): RNFirebase.messaging.Messaging;
/** /**
* RNFirebase provides crash reporting for your app out of the box. * RNFirebase provides crash reporting for your app out of the box.
* Please note crashes do not appear in real-time on the console, * Please note crashes do not appear in real-time on the console,
@ -37,9 +45,12 @@ declare module "react-native-firebase" {
* such as a pre-caught exception this is possible by using the report method. * such as a pre-caught exception this is possible by using the report method.
*/ */
crash(): RNFirebase.crash.Crash; crash(): RNFirebase.crash.Crash;
apps: Array<string>; apps: Array<string>;
googleApiAvailability: RNFirebase.GoogleApiAvailabilityType; googleApiAvailability: RNFirebase.GoogleApiAvailabilityType;
static initializeApp(options?: any | RNFirebase.configurationOptions, name?: string): FireBase; static initializeApp(options?: any | RNFirebase.configurationOptions, name?: string): FireBase;
[key: string]: any; [key: string]: any;
} }
@ -56,10 +67,10 @@ declare module "react-native-firebase" {
}; };
/** /**
* pass custom options by passing an object with configuration options. * pass custom options by passing an object with configuration options.
* The configuration object will be generated first by the native configuration object, if set and then will be overridden if passed in JS. * The configuration object will be generated first by the native configuration object, if set and then will be overridden if passed in JS.
* That is, all of the following key/value pairs are optional if the native configuration is set. * That is, all of the following key/value pairs are optional if the native configuration is set.
*/ */
interface configurationOptions { interface configurationOptions {
/** /**
* default false * default false
@ -74,7 +85,7 @@ declare module "react-native-firebase" {
*/ */
persistence?: boolean; persistence?: boolean;
/** /**
* Default from app [NSBundle mainBundle] The bundle ID for the app to be bundled with * Default from app [NSBundle mainBundle] The bundle ID for the app to be bundled with
*/ */
bundleID?: string; bundleID?: string;
/** /**
@ -103,7 +114,7 @@ declare module "react-native-firebase" {
*/ */
androidClientID?: string; androidClientID?: string;
/** /**
* default "" * default ""
* The Project number from the Google Developer's console used to configure Google Cloud Messaging * The Project number from the Google Developer's console used to configure Google Cloud Messaging
*/ */
GCMSenderID?: string; GCMSenderID?: string;
@ -127,12 +138,10 @@ declare module "react-native-firebase" {
namespace storage { namespace storage {
interface StorageTask<T> extends Promise<T> { interface StorageTask<T> extends Promise<T> {
on( on(event: TaskEvent,
event: TaskEvent, nextOrObserver: (snapshot: any) => any,
nextOrObserver: (snapshot: any) => any, error: (error: RnError) => any,
error: (error: RnError) => any, complete: (complete: any) => any): any
complete: (complete: any) => any
): any
/** /**
* is not currently supported by react-native-firebase * is not currently supported by react-native-firebase
*/ */
@ -183,17 +192,13 @@ declare module "react-native-firebase" {
name: string; name: string;
parent: storage.Reference | null; parent: storage.Reference | null;
put(data: any | Uint8Array | ArrayBuffer, put(data: any | Uint8Array | ArrayBuffer,
metadata?: storage.UploadMetadata): metadata?: storage.UploadMetadata): storage.UploadTask;
storage.UploadTask; putString(data: string, format?: storage.StringFormat,
putString( metadata?: storage.UploadMetadata): storage.UploadTask;
data: string, format?: storage.StringFormat,
metadata?: storage.UploadMetadata):
storage.UploadTask;
root: storage.Reference; root: storage.Reference;
storage: storage.Storage; storage: storage.Storage;
toString(): string; toString(): string;
updateMetadata(metadata: storage.SettableMetadata): updateMetadata(metadata: storage.SettableMetadata): Promise<any>;
Promise<any>;
} }
interface UploadMetadata extends storage.SettableMetadata { interface UploadMetadata extends storage.SettableMetadata {
md5Hash?: string | null; md5Hash?: string | null;
@ -219,13 +224,12 @@ declare module "react-native-firebase" {
cancel(): boolean; cancel(): boolean;
catch(onRejected: (a: RnError) => any): Promise<any>; catch(onRejected: (a: RnError) => any): Promise<any>;
on(event: storage.TaskEvent, nextOrObserver?: null | Object, on(event: storage.TaskEvent, nextOrObserver?: null | Object,
error?: ((a: RnError) => any) | null, complete?: (() => any) | null): Function; error?: ((a: RnError) => any) | null, complete?: (() => any) | null): Function;
pause(): boolean; pause(): boolean;
resume(): boolean; resume(): boolean;
snapshot: storage.UploadTaskSnapshot; snapshot: storage.UploadTaskSnapshot;
then( then(onFulfilled?: ((a: storage.UploadTaskSnapshot) => any) | null,
onFulfilled?: ((a: storage.UploadTaskSnapshot) => any) | null, onRejected?: ((a: RnError) => any) | null): Promise<any>;
onRejected?: ((a: RnError) => any) | null): Promise<any>;
} }
interface UploadTaskSnapshot { interface UploadTaskSnapshot {
@ -310,18 +314,15 @@ declare module "react-native-firebase" {
limitToFirst(limit: number): database.Query; limitToFirst(limit: number): database.Query;
limitToLast(limit: number): database.Query; limitToLast(limit: number): database.Query;
off(eventType?: string, off(eventType?: string,
callback?: (a: database.DataSnapshot, b?: string | null) => any, callback?: (a: database.DataSnapshot, b?: string | null) => any,
context?: Object | null): any; context?: Object | null): any;
on(eventType: string, on(eventType: string,
callback: (a: database.DataSnapshot | null, b?: string) => any, callback: (a: database.DataSnapshot | null, b?: string) => any,
cancelCallbackOrContext?: Object | null, context?: Object | null): cancelCallbackOrContext?: Object | null, context?: Object | null): (a: database.DataSnapshot | null, b?: string) => any;
(a: database.DataSnapshot | null, b?: string) => any; once(eventType: string,
once( successCallback?: (a: database.DataSnapshot, b?: string) => any,
eventType: string, failureCallbackOrContext?: Object | null,
successCallback?: context?: Object | null): Promise<any>;
(a: database.DataSnapshot, b?: string) => any,
failureCallbackOrContext?: Object | null,
context?: Object | null): Promise<any>;
orderByChild(path: string): database.Query; orderByChild(path: string): database.Query;
orderByKey(): database.Query; orderByKey(): database.Query;
orderByPriority(): database.Query; orderByPriority(): database.Query;
@ -356,18 +357,14 @@ declare module "react-native-firebase" {
remove(onComplete?: (a: RnError | null) => any): Promise<any>; remove(onComplete?: (a: RnError | null) => any): Promise<any>;
root: database.Reference; root: database.Reference;
set(value: any, onComplete?: (a: RnError | null) => any): Promise<any>; set(value: any, onComplete?: (a: RnError | null) => any): Promise<any>;
setPriority( setPriority(priority: string | number | null,
priority: string | number | null, onComplete: (a: RnError | null) => any): Promise<any>;
onComplete: (a: RnError | null) => any): Promise<any>; setWithPriority(newVal: any, newPriority: string | number | null,
setWithPriority( onComplete?: (a: RnError | null) => any): Promise<any>;
newVal: any, newPriority: string | number | null, transaction(transactionUpdate: (a: any) => any,
onComplete?: (a: RnError | null) => any): Promise<any>; onComplete?: (a: RnError | null, b: boolean,
transaction( c: database.DataSnapshot | null) => any,
transactionUpdate: (a: any) => any, applyLocally?: boolean): Promise<any>;
onComplete?:
(a: RnError | null, b: boolean,
c: database.DataSnapshot | null) => any,
applyLocally?: boolean): Promise<any>;
update(values: Object, onComplete?: (a: RnError | null) => any): Promise<any>; update(values: Object, onComplete?: (a: RnError | null) => any): Promise<any>;
} }
} }
@ -491,6 +488,17 @@ declare module "react-native-firebase" {
token: string, token: string,
secret: string secret: string
} }
interface ActionCodeInfo {
email: string,
error: string,
fromEmail: string,
verifyEmail: string,
recoverEmail: string,
passwordReset: string
}
namespace auth { namespace auth {
interface Auth { interface Auth {
@ -507,9 +515,8 @@ declare module "react-native-firebase" {
* This method returns a unsubscribe function to stop listening to events. * This method returns a unsubscribe function to stop listening to events.
* Always ensure you unsubscribe from the listener when no longer needed to prevent updates to components no longer in use. * Always ensure you unsubscribe from the listener when no longer needed to prevent updates to components no longer in use.
*/ */
onAuthStateChanged( onAuthStateChanged(nextOrObserver: Object, error?: (a: RnError) => any,
nextOrObserver: Object, error?: (a: RnError) => any, completed?: () => any): () => any;
completed?: () => any): () => any;
/** /**
* We can create a user by calling the createUserWithEmailAndPassword() function. * We can create a user by calling the createUserWithEmailAndPassword() function.
* The method accepts two parameters, an email and a password. * The method accepts two parameters, an email and a password.
@ -543,6 +550,21 @@ declare module "react-native-firebase" {
* the email will contain a password reset link rather than a code. * the email will contain a password reset link rather than a code.
*/ */
sendPasswordResetEmail(email: string): Promise<void> sendPasswordResetEmail(email: string): Promise<void>
/**
* Completes the password reset process, given a confirmation code and new password.
*/
confirmPasswordReset(code: string, newPassword: string): Promise<any>
/**
* Applies a verification code sent to the user by email or other out-of-band mechanism.
*/
applyActionCode(code: string): Promise<any>
/**
* Checks a verification code sent to the user by email or other out-of-band mechanism.
*/
checkActionCode(code: string): Promise<ActionCodeInfo>
/** /**
* Completes the password reset process, * Completes the password reset process,
* given a confirmation code and new password. * given a confirmation code and new password.

View File

@ -340,6 +340,57 @@ RCT_EXPORT_METHOD(confirmPasswordReset:(NSString *)code newPassword:(NSString *)
}]; }];
} }
/**
* applyActionCode
*
* @param NSString code
* @param RCTPromiseResolveBlock resolve
* @param RCTPromiseRejectBlock reject
* @return
*/
RCT_EXPORT_METHOD(applyActionCode:(NSString *)code resolver:(RCTPromiseResolveBlock) resolve rejecter:(RCTPromiseRejectBlock) reject) {
[[FIRAuth auth] applyActionCode:code completion:^(NSError *_Nullable error) {
if (error) {
[self promiseRejectAuthException:reject error:error];
} else {
[self promiseNoUser:resolve rejecter:reject isError:NO];
}
}];
}
/**
* checkActionCode
*
* @param NSString code
* @param RCTPromiseResolveBlock resolve
* @param RCTPromiseRejectBlock reject
* @return
*/
RCT_EXPORT_METHOD(checkActionCode:(NSString *) code resolver:(RCTPromiseResolveBlock) resolve rejecter:(RCTPromiseRejectBlock) reject) {
[[FIRAuth auth] checkActionCode:code completion:^(FIRActionCodeInfo *_Nullable info, NSError *_Nullable error){
if (error) {
[self promiseRejectAuthException:reject error:error];
} else {
NSDictionary * result = @{
@"data": @{
@"email": [info dataForKey:FIRActionCodeEmailKey],
@"fromEmail": [info dataForKey:FIRActionCodeFromEmailKey],
}
};
// TODO action code operation codes?
/*
FIRActionCodeOperationUnknown = 0,
FIRActionCodeOperationPasswordReset = 1,
FIRActionCodeOperationVerifyEmail = 2
*/
resolve(result);
}
}];
}
/** /**
sendPasswordResetEmail sendPasswordResetEmail

View File

@ -165,6 +165,27 @@ export default class Auth extends Base {
return FirebaseAuth.confirmPasswordReset(code, newPassword); return FirebaseAuth.confirmPasswordReset(code, newPassword);
} }
/**
* Applies a verification code sent to the user by email or other out-of-band mechanism.
*
* @link https://firebase.google.com/docs/reference/js/firebase.auth.Auth#applyActionCode
* @param code
* @return {Promise.<Null>}
*/
applyActionCode(code: string): Promise<Any> {
return FirebaseAuth.applyActionCode(code);
}
/**
* Checks a verification code sent to the user by email or other out-of-band mechanism.
*
* @link https://firebase.google.com/docs/reference/js/firebase.auth.Auth#checkActionCode
* @param code
* @return {Promise.<Any>|Promise<ActionCodeInfo>}
*/
checkActionCode(code: string): Promise<Any> {
return FirebaseAuth.checkActionCode(code);
}
/** /**
* Get the currently signed in user * Get the currently signed in user

View File

@ -1,6 +1,6 @@
{ {
"name": "react-native-firebase", "name": "react-native-firebase",
"version": "2.0.1", "version": "2.0.2",
"author": "Invertase <contact@invertase.io> (http://invertase.io)", "author": "Invertase <contact@invertase.io> (http://invertase.io)",
"description": "A well tested, feature rich Firebase implementation for React Native, supporting iOS & Android. Individual module support for Auth, Database, Messaging, Remote Config, Storage, Admob, Analytics, Crash Reporting, and Performance.", "description": "A well tested, feature rich Firebase implementation for React Native, supporting iOS & Android. Individual module support for Auth, Database, Messaging, Remote Config, Storage, Admob, Analytics, Crash Reporting, and Performance.",
"main": "index", "main": "index",