2017-03-09 15:26:28 +00:00
# import "RNFirebaseAuth.h"
# import "RNFirebaseEvents.h"
2017-10-26 10:55:07 +00:00
# import "RNFirebaseUtil.h"
2017-06-29 16:24:34 +00:00
# import "RCTDefines.h"
2017-03-09 15:26:28 +00:00
2017-05-25 14:33:41 +00:00
# if __has _include ( < FirebaseAuth / FIRAuth . h > )
2017-06-29 16:24:34 +00:00
2017-05-25 14:33:41 +00:00
@ implementation RNFirebaseAuth
RCT_EXPORT _MODULE ( ) ;
2017-03-09 15:26:28 +00:00
2017-07-17 19:56:08 +00:00
- ( id ) init {
self = [ super init ] ;
if ( self ! = nil ) {
_authStateHandlers = [ [ NSMutableDictionary alloc ] init ] ;
2017-09-21 15:48:54 +00:00
_idTokenHandlers = [ [ NSMutableDictionary alloc ] init ] ;
2017-07-17 19:56:08 +00:00
}
return self ;
}
2017-03-17 19:08:51 +00:00
/ * *
addAuthStateListener
2017-05-31 14:22:15 +00:00
2017-03-17 19:08:51 +00:00
* /
2017-06-29 16:24:34 +00:00
RCT_EXPORT _METHOD ( addAuthStateListener :
2018-01-03 20:00:38 +00:00
( NSString * ) appDisplayName ) {
FIRApp * firApp = [ RNFirebaseUtil getApp : appDisplayName ] ;
2017-07-17 19:56:08 +00:00
2018-01-03 20:00:38 +00:00
if ( ! [ _authStateHandlers valueForKey : firApp . name ] ) {
2017-07-17 19:56:08 +00:00
FIRAuthStateDidChangeListenerHandle newListenerHandle = [ [ FIRAuth authWithApp : firApp ] addAuthStateDidChangeListener : ^ ( FIRAuth * _Nonnull auth , FIRUser * _Nullable user ) {
if ( user ! = nil ) {
2018-01-24 09:46:39 +00:00
[ RNFirebaseUtil sendJSEventWithAppName : self app : firApp name : AUTH_STATE _CHANGED _EVENT body : @ { @ "user" : [ self firebaseUserToDict : user ] } ] ;
2017-07-17 19:56:08 +00:00
} else {
2018-01-24 09:46:39 +00:00
[ RNFirebaseUtil sendJSEventWithAppName : self app : firApp name : AUTH_STATE _CHANGED _EVENT body : @ { } ] ;
2017-07-17 19:56:08 +00:00
}
} ] ;
2018-01-03 20:00:38 +00:00
_authStateHandlers [ firApp . name ] = [ NSValue valueWithNonretainedObject : newListenerHandle ] ;
2017-07-17 19:56:08 +00:00
}
2017-03-17 19:08:51 +00:00
}
/ * *
removeAuthStateListener
2017-05-31 14:22:15 +00:00
2017-03-17 19:08:51 +00:00
* /
2017-06-29 16:24:34 +00:00
RCT_EXPORT _METHOD ( removeAuthStateListener :
2018-01-03 20:00:38 +00:00
( NSString * ) appDisplayName ) {
FIRApp * firApp = [ RNFirebaseUtil getApp : appDisplayName ] ;
2017-06-29 16:24:34 +00:00
2018-01-03 20:00:38 +00:00
if ( [ _authStateHandlers valueForKey : firApp . name ] ) {
[ [ FIRAuth authWithApp : firApp ] removeAuthStateDidChangeListener : [ _authStateHandlers valueForKey : firApp . name ] ] ;
[ _authStateHandlers removeObjectForKey : firApp . name ] ;
2017-03-17 19:08:51 +00:00
}
}
2017-09-21 15:48:54 +00:00
/ * *
addIdTokenListener
* /
RCT_EXPORT _METHOD ( addIdTokenListener :
2018-01-03 20:00:38 +00:00
( NSString * ) appDisplayName ) {
FIRApp * firApp = [ RNFirebaseUtil getApp : appDisplayName ] ;
2017-09-21 15:48:54 +00:00
2018-01-03 20:00:38 +00:00
if ( ! [ _idTokenHandlers valueForKey : firApp . name ] ) {
2017-09-21 15:48:54 +00:00
FIRIDTokenDidChangeListenerHandle newListenerHandle = [ [ FIRAuth authWithApp : firApp ] addIDTokenDidChangeListener : ^ ( FIRAuth * _Nonnull auth , FIRUser * _Nullable user ) {
if ( user ! = nil ) {
2018-01-24 09:46:39 +00:00
[ RNFirebaseUtil sendJSEventWithAppName : self app : firApp name : AUTH_ID _TOKEN _CHANGED _EVENT body : @ { @ "user" : [ self firebaseUserToDict : user ] } ] ;
2017-09-21 15:48:54 +00:00
} else {
2018-01-24 09:46:39 +00:00
[ RNFirebaseUtil sendJSEventWithAppName : self app : firApp name : AUTH_ID _TOKEN _CHANGED _EVENT body : @ { } ] ;
2017-09-21 15:48:54 +00:00
}
} ] ;
2018-01-03 20:00:38 +00:00
_idTokenHandlers [ firApp . name ] = [ NSValue valueWithNonretainedObject : newListenerHandle ] ;
2017-09-21 15:48:54 +00:00
}
}
/ * *
removeAuthStateListener
* /
RCT_EXPORT _METHOD ( removeIdTokenListener :
2018-01-03 20:00:38 +00:00
( NSString * ) appDisplayName ) {
FIRApp * firApp = [ RNFirebaseUtil getApp : appDisplayName ] ;
if ( [ _idTokenHandlers valueForKey : firApp . name ] ) {
[ [ FIRAuth authWithApp : firApp ] removeIDTokenDidChangeListener : [ _idTokenHandlers valueForKey : firApp . name ] ] ;
[ _idTokenHandlers removeObjectForKey : firApp . name ] ;
2017-09-21 15:48:54 +00:00
}
}
2017-06-29 16:24:34 +00:00
2017-03-14 19:04:16 +00:00
/ * *
signOut
2017-05-31 14:22:15 +00:00
2017-03-14 19:04:16 +00:00
@ param RCTPromiseResolveBlock resolve
@ param RCTPromiseRejectBlock reject
@ return
* /
2017-06-29 16:24:34 +00:00
RCT_EXPORT _METHOD ( signOut :
2018-01-03 20:00:38 +00:00
( NSString * ) appDisplayName
2017-06-30 16:23:32 +00:00
resolver :
( RCTPromiseResolveBlock ) resolve
2017-06-29 16:24:34 +00:00
rejecter :
( RCTPromiseRejectBlock ) reject ) {
2018-01-03 20:00:38 +00:00
FIRApp * firApp = [ RNFirebaseUtil getApp : appDisplayName ] ;
2017-06-30 16:23:32 +00:00
2017-11-10 22:00:42 +00:00
FIRUser * user = [ FIRAuth authWithApp : firApp ] . currentUser ;
2017-05-31 14:22:15 +00:00
2017-03-14 19:04:16 +00:00
if ( user ) {
NSError * error ;
2017-06-30 16:23:32 +00:00
[ [ FIRAuth authWithApp : firApp ] signOut : & error ] ;
2017-03-14 19:04:16 +00:00
if ( ! error ) [ self promiseNoUser : resolve rejecter : reject isError : NO ] ;
2017-03-17 21:41:17 +00:00
else [ self promiseRejectAuthException : reject error : error ] ;
2017-03-14 19:04:16 +00:00
} else {
[ self promiseNoUser : resolve rejecter : reject isError : YES ] ;
2017-03-09 15:26:28 +00:00
}
}
2017-03-14 19:04:16 +00:00
/ * *
signInAnonymously
2017-05-31 14:22:15 +00:00
2017-03-14 19:04:16 +00:00
@ param RCTPromiseResolveBlock resolve
@ param RCTPromiseRejectBlock reject
@ return
* /
2018-01-24 09:46:39 +00:00
RCT_EXPORT _METHOD ( signInAnonymously : ( NSString * ) appDisplayName
resolver : ( RCTPromiseResolveBlock ) resolve
rejecter : ( RCTPromiseRejectBlock ) reject ) {
2018-01-03 20:00:38 +00:00
FIRApp * firApp = [ RNFirebaseUtil getApp : appDisplayName ] ;
2017-06-30 16:23:32 +00:00
[ [ FIRAuth authWithApp : firApp ] signInAnonymouslyWithCompletion : ^ ( FIRUser * user , NSError * error ) {
2017-03-14 19:04:16 +00:00
if ( error ) {
2017-03-17 21:41:17 +00:00
[ self promiseRejectAuthException : reject error : error ] ;
2017-03-14 19:04:16 +00:00
} else {
[ self promiseWithUser : resolve rejecter : reject user : user ] ;
}
} ] ;
2018-01-24 09:46:39 +00:00
}
2017-05-31 14:22:15 +00:00
2018-01-24 09:46:39 +00:00
/ * *
signInAnonymouslyAndRetrieveData
@ param RCTPromiseResolveBlock resolve
@ param RCTPromiseRejectBlock reject
@ return
* /
RCT_EXPORT _METHOD ( signInAnonymouslyAndRetrieveData : ( NSString * ) appDisplayName
resolver : ( RCTPromiseResolveBlock ) resolve
rejecter : ( RCTPromiseRejectBlock ) reject ) {
FIRApp * firApp = [ RNFirebaseUtil getApp : appDisplayName ] ;
[ [ FIRAuth authWithApp : firApp ] signInAnonymouslyAndRetrieveDataWithCompletion : ^ ( FIRAuthDataResult * authResult , NSError * error ) {
if ( error ) {
[ self promiseRejectAuthException : reject error : error ] ;
} else {
[ self promiseWithAuthResult : resolve rejecter : reject authResult : authResult ] ;
}
} ] ;
2017-03-14 19:04:16 +00:00
}
/ * *
signInWithEmailAndPassword
2017-05-31 14:22:15 +00:00
2017-03-14 19:04:16 +00:00
@ param NSString NSString email
@ param NSString NSString password
@ param RCTPromiseResolveBlock resolve
@ param RCTPromiseRejectBlock reject
@ return return
* /
2018-01-24 09:46:39 +00:00
RCT_EXPORT _METHOD ( signInWithEmailAndPassword : ( NSString * ) appDisplayName
email : ( NSString * ) email
pass : ( NSString * ) password
resolver : ( RCTPromiseResolveBlock ) resolve
rejecter : ( RCTPromiseRejectBlock ) reject ) {
2018-01-03 20:00:38 +00:00
FIRApp * firApp = [ RNFirebaseUtil getApp : appDisplayName ] ;
2017-06-30 16:23:32 +00:00
[ [ FIRAuth authWithApp : firApp ] signInWithEmail : email password : password completion : ^ ( FIRUser * user , NSError * error ) {
2017-03-14 19:04:16 +00:00
if ( error ) {
2017-03-17 21:41:17 +00:00
[ self promiseRejectAuthException : reject error : error ] ;
2017-03-14 19:04:16 +00:00
} else {
[ self promiseWithUser : resolve rejecter : reject user : user ] ;
}
} ] ;
}
2018-01-24 09:46:39 +00:00
/ * *
signInAndRetrieveDataWithEmailAndPassword
@ param NSString NSString email
@ param NSString NSString password
@ param RCTPromiseResolveBlock resolve
@ param RCTPromiseRejectBlock reject
@ return return
* /
RCT_EXPORT _METHOD ( signInAndRetrieveDataWithEmailAndPassword : ( NSString * ) appDisplayName
email : ( NSString * ) email
pass : ( NSString * ) password
resolver : ( RCTPromiseResolveBlock ) resolve
rejecter : ( RCTPromiseRejectBlock ) reject ) {
FIRApp * firApp = [ RNFirebaseUtil getApp : appDisplayName ] ;
[ [ FIRAuth authWithApp : firApp ] signInAndRetrieveDataWithEmail : email password : password completion : ^ ( FIRAuthDataResult * authResult , NSError * error ) {
if ( error ) {
[ self promiseRejectAuthException : reject error : error ] ;
} else {
[ self promiseWithAuthResult : resolve rejecter : reject authResult : authResult ] ;
}
} ] ;
}
2017-03-14 19:04:16 +00:00
/ * *
createUserWithEmailAndPassword
2017-05-31 14:22:15 +00:00
2017-03-14 19:04:16 +00:00
@ param NSString NSString email
@ param NSString NSString password
@ param RCTPromiseResolveBlock resolve
@ param RCTPromiseRejectBlock reject
@ return return
* /
2018-01-24 09:46:39 +00:00
RCT_EXPORT _METHOD ( createUserWithEmailAndPassword : ( NSString * ) appDisplayName
email : ( NSString * ) email
pass : ( NSString * ) password
resolver : ( RCTPromiseResolveBlock ) resolve
rejecter : ( RCTPromiseRejectBlock ) reject ) {
2018-01-03 20:00:38 +00:00
FIRApp * firApp = [ RNFirebaseUtil getApp : appDisplayName ] ;
2017-06-30 16:23:32 +00:00
[ [ FIRAuth authWithApp : firApp ] createUserWithEmail : email password : password completion : ^ ( FIRUser * user , NSError * error ) {
2017-03-14 19:04:16 +00:00
if ( error ) {
2017-03-17 21:41:17 +00:00
[ self promiseRejectAuthException : reject error : error ] ;
2017-03-14 19:04:16 +00:00
} else {
[ self promiseWithUser : resolve rejecter : reject user : user ] ;
}
} ] ;
}
2018-01-24 09:46:39 +00:00
/ * *
createUserAndRetrieveDataWithEmailAndPassword
@ param NSString NSString email
@ param NSString NSString password
@ param RCTPromiseResolveBlock resolve
@ param RCTPromiseRejectBlock reject
@ return return
* /
RCT_EXPORT _METHOD ( createUserAndRetrieveDataWithEmailAndPassword : ( NSString * ) appDisplayName
email : ( NSString * ) email
pass : ( NSString * ) password
resolver : ( RCTPromiseResolveBlock ) resolve
rejecter : ( RCTPromiseRejectBlock ) reject ) {
FIRApp * firApp = [ RNFirebaseUtil getApp : appDisplayName ] ;
[ [ FIRAuth authWithApp : firApp ] createUserAndRetrieveDataWithEmail : email password : password
completion : ^ ( FIRAuthDataResult * _Nullable authResult , NSError * _Nullable error ) {
if ( error ) {
[ self promiseRejectAuthException : reject error : error ] ;
} else {
[ self promiseWithAuthResult : resolve rejecter : reject authResult : authResult ] ;
}
} ] ;
}
2017-03-14 19:04:16 +00:00
/ * *
deleteUser
2017-05-31 14:22:15 +00:00
2017-03-14 19:04:16 +00:00
@ param RCTPromiseResolveBlock resolve
@ param RCTPromiseRejectBlock reject
@ return return
* /
2017-06-29 16:24:34 +00:00
RCT_EXPORT _METHOD ( delete :
2018-01-03 20:00:38 +00:00
( NSString * ) appDisplayName
2017-06-30 16:23:32 +00:00
resolver :
( RCTPromiseResolveBlock ) resolve
2017-06-29 16:24:34 +00:00
rejecter :
( RCTPromiseRejectBlock ) reject ) {
2018-01-03 20:00:38 +00:00
FIRApp * firApp = [ RNFirebaseUtil getApp : appDisplayName ] ;
2017-06-30 16:23:32 +00:00
FIRUser * user = [ FIRAuth authWithApp : firApp ] . currentUser ;
2017-05-31 14:22:15 +00:00
2017-03-14 19:04:16 +00:00
if ( user ) {
[ user deleteWithCompletion : ^ ( NSError * _Nullable error ) {
if ( error ) {
2017-03-17 21:41:17 +00:00
[ self promiseRejectAuthException : reject error : error ] ;
2017-03-14 19:04:16 +00:00
} else {
[ self promiseNoUser : resolve rejecter : reject isError : NO ] ;
}
} ] ;
} else {
[ self promiseNoUser : resolve rejecter : reject isError : YES ] ;
}
}
2017-03-18 00:31:02 +00:00
/ * *
reload
2017-05-31 14:22:15 +00:00
2017-03-18 00:31:02 +00:00
@ param RCTPromiseResolveBlock resolve
@ param RCTPromiseRejectBlock reject
@ return return
* /
2017-06-29 16:24:34 +00:00
RCT_EXPORT _METHOD ( reload :
2018-01-03 20:00:38 +00:00
( NSString * ) appDisplayName
2017-06-30 16:23:32 +00:00
resolver :
( RCTPromiseResolveBlock ) resolve
2017-06-29 16:24:34 +00:00
rejecter :
( RCTPromiseRejectBlock ) reject ) {
2018-01-03 20:00:38 +00:00
FIRApp * firApp = [ RNFirebaseUtil getApp : appDisplayName ] ;
2017-06-30 16:23:32 +00:00
FIRUser * user = [ FIRAuth authWithApp : firApp ] . currentUser ;
2017-05-31 14:22:15 +00:00
2017-03-18 00:31:02 +00:00
if ( user ) {
2017-10-26 14:10:00 +00:00
[ self reloadAndReturnUser : user resolver : resolve rejecter : reject ] ;
2017-03-18 00:31:02 +00:00
} else {
[ self promiseNoUser : resolve rejecter : reject isError : YES ] ;
}
}
/ * *
sendEmailVerification
2017-05-31 14:22:15 +00:00
2017-03-18 00:31:02 +00:00
@ param RCTPromiseResolveBlock resolve
@ param RCTPromiseRejectBlock reject
@ return return
* /
2018-01-03 20:00:38 +00:00
RCT_EXPORT _METHOD ( sendEmailVerification : ( NSString * ) appDisplayName
2017-12-07 12:36:51 +00:00
actionCodeSettings : ( NSDictionary * ) actionCodeSettings
resolver : ( RCTPromiseResolveBlock ) resolve
rejecter : ( RCTPromiseRejectBlock ) reject ) {
2018-01-03 20:00:38 +00:00
FIRApp * firApp = [ RNFirebaseUtil getApp : appDisplayName ] ;
2017-05-31 14:22:15 +00:00
2017-06-30 16:23:32 +00:00
FIRUser * user = [ FIRAuth authWithApp : firApp ] . currentUser ;
2017-03-18 00:31:02 +00:00
if ( user ) {
2017-12-07 12:36:51 +00:00
id handler = ^ ( NSError * _Nullable error ) {
2017-03-18 00:31:02 +00:00
if ( error ) {
[ self promiseRejectAuthException : reject error : error ] ;
} else {
2017-06-30 16:23:32 +00:00
FIRUser * userAfterUpdate = [ FIRAuth authWithApp : firApp ] . currentUser ;
2017-06-20 18:49:45 +00:00
[ self promiseWithUser : resolve rejecter : reject user : userAfterUpdate ] ;
2017-03-18 00:31:02 +00:00
}
2017-12-07 12:36:51 +00:00
} ;
if ( actionCodeSettings ) {
FIRActionCodeSettings * settings = [ self buildActionCodeSettings : actionCodeSettings ] ;
[ user sendEmailVerificationWithActionCodeSettings : settings completion : handler ] ;
} else {
[ user sendEmailVerificationWithCompletion : handler ] ;
}
2017-03-18 00:31:02 +00:00
} else {
[ self promiseNoUser : resolve rejecter : reject isError : YES ] ;
}
}
/ * *
updateEmail
2017-05-31 14:22:15 +00:00
2017-03-18 00:31:02 +00:00
@ param NSString email
@ param RCTPromiseResolveBlock resolve
@ param RCTPromiseRejectBlock reject
@ return return
* /
2017-06-29 16:24:34 +00:00
RCT_EXPORT _METHOD ( updateEmail :
2018-01-03 20:00:38 +00:00
( NSString * ) appDisplayName
2017-06-30 16:23:32 +00:00
email :
( NSString * ) email
2017-06-29 16:24:34 +00:00
resolver :
( RCTPromiseResolveBlock ) resolve
rejecter :
( RCTPromiseRejectBlock ) reject ) {
2018-01-03 20:00:38 +00:00
FIRApp * firApp = [ RNFirebaseUtil getApp : appDisplayName ] ;
2017-06-30 16:23:32 +00:00
FIRUser * user = [ FIRAuth authWithApp : firApp ] . currentUser ;
2017-05-31 14:22:15 +00:00
2017-03-18 00:31:02 +00:00
if ( user ) {
[ user updateEmail : email completion : ^ ( NSError * _Nullable error ) {
if ( error ) {
[ self promiseRejectAuthException : reject error : error ] ;
} else {
2017-10-26 14:22:42 +00:00
[ self reloadAndReturnUser : user resolver : resolve rejecter : reject ] ;
2017-03-18 00:31:02 +00:00
}
} ] ;
} else {
[ self promiseNoUser : resolve rejecter : reject isError : YES ] ;
}
}
2017-03-18 00:41:10 +00:00
/ * *
updatePassword
2017-05-31 14:22:15 +00:00
2017-03-18 00:41:10 +00:00
@ param NSString password
@ param RCTPromiseResolveBlock resolve
@ param RCTPromiseRejectBlock reject
@ return return
* /
2017-06-29 16:24:34 +00:00
RCT_EXPORT _METHOD ( updatePassword :
2018-01-03 20:00:38 +00:00
( NSString * ) appDisplayName
2017-06-30 16:23:32 +00:00
password :
( NSString * ) password
2017-06-29 16:24:34 +00:00
resolver :
( RCTPromiseResolveBlock ) resolve
rejecter :
( RCTPromiseRejectBlock ) reject ) {
2018-01-03 20:00:38 +00:00
FIRApp * firApp = [ RNFirebaseUtil getApp : appDisplayName ] ;
2017-06-30 16:23:32 +00:00
2017-11-10 22:03:15 +00:00
FIRUser * user = [ FIRAuth authWithApp : firApp ] . currentUser ;
2017-05-31 14:22:15 +00:00
2017-03-18 00:41:10 +00:00
if ( user ) {
[ user updatePassword : password completion : ^ ( NSError * _Nullable error ) {
if ( error ) {
[ self promiseRejectAuthException : reject error : error ] ;
} else {
2017-06-30 16:23:32 +00:00
FIRUser * userAfterUpdate = [ FIRAuth authWithApp : firApp ] . currentUser ;
2017-03-18 00:41:10 +00:00
[ self promiseWithUser : resolve rejecter : reject user : userAfterUpdate ] ;
}
} ] ;
} else {
[ self promiseNoUser : resolve rejecter : reject isError : YES ] ;
}
}
2017-03-14 19:04:16 +00:00
2017-03-18 01:10:22 +00:00
/ * *
updateProfile
2017-05-31 14:22:15 +00:00
2017-03-18 01:10:22 +00:00
@ param NSDictionary props
@ param RCTPromiseResolveBlock resolve
@ param RCTPromiseRejectBlock reject
@ return return
* /
2017-06-29 16:24:34 +00:00
RCT_EXPORT _METHOD ( updateProfile :
2018-01-03 20:00:38 +00:00
( NSString * ) appDisplayName
2017-06-30 16:23:32 +00:00
props :
( NSDictionary * ) props
2017-06-29 16:24:34 +00:00
resolver :
( RCTPromiseResolveBlock ) resolve
rejecter :
( RCTPromiseRejectBlock ) reject ) {
2018-01-03 20:00:38 +00:00
FIRApp * firApp = [ RNFirebaseUtil getApp : appDisplayName ] ;
2017-06-30 16:23:32 +00:00
FIRUser * user = [ FIRAuth authWithApp : firApp ] . currentUser ;
2017-05-31 14:22:15 +00:00
2017-03-18 01:10:22 +00:00
if ( user ) {
FIRUserProfileChangeRequest * changeRequest = [ user profileChangeRequest ] ;
NSMutableArray * allKeys = [ [ props allKeys ] mutableCopy ] ;
2017-05-31 14:22:15 +00:00
2017-03-18 01:10:22 +00:00
for ( NSString * key in allKeys ) {
@ try {
if ( [ key isEqualToString : @ "photoURL" ] ) {
NSURL * url = [ NSURL URLWithString : [ props valueForKey : key ] ] ;
[ changeRequest setValue : url forKey : key ] ;
} else {
2017-05-25 14:33:41 +00:00
[ changeRequest setValue : props [ key ] forKey : key ] ;
2017-03-18 01:10:22 +00:00
}
} @ catch ( NSException * exception ) {
NSLog ( @ "Exception occurred while configuring: %@" , exception ) ;
}
}
2017-05-31 14:22:15 +00:00
2017-03-18 01:10:22 +00:00
[ changeRequest commitChangesWithCompletion : ^ ( NSError * _Nullable error ) {
if ( error ) {
[ self promiseRejectAuthException : reject error : error ] ;
} else {
2017-10-26 14:10:00 +00:00
[ self reloadAndReturnUser : user resolver : resolve rejecter : reject ] ;
2017-03-18 01:10:22 +00:00
}
} ] ;
} else {
[ self promiseNoUser : resolve rejecter : reject isError : YES ] ;
}
}
2017-03-16 12:35:03 +00:00
/ * *
getToken
2017-05-31 14:22:15 +00:00
2017-03-16 12:35:03 +00:00
@ param RCTPromiseResolveBlock resolve
@ param RCTPromiseRejectBlock reject
@ return
* /
2017-06-29 16:24:34 +00:00
RCT_EXPORT _METHOD ( getToken :
2018-01-03 20:00:38 +00:00
( NSString * ) appDisplayName
2017-06-30 16:23:32 +00:00
forceRefresh :
( BOOL ) forceRefresh
2017-06-29 16:24:34 +00:00
resolver :
( RCTPromiseResolveBlock ) resolve
rejecter :
( RCTPromiseRejectBlock ) reject ) {
2018-01-03 20:00:38 +00:00
FIRApp * firApp = [ RNFirebaseUtil getApp : appDisplayName ] ;
2017-06-30 16:23:32 +00:00
FIRUser * user = [ FIRAuth authWithApp : firApp ] . currentUser ;
2017-05-31 14:22:15 +00:00
2017-03-16 12:35:03 +00:00
if ( user ) {
2017-06-30 16:23:32 +00:00
[ user getIDTokenForcingRefresh : ( BOOL ) forceRefresh completion : ^ ( NSString * token , NSError * _Nullable error ) {
2017-03-16 12:35:03 +00:00
if ( error ) {
2017-03-17 21:41:17 +00:00
[ self promiseRejectAuthException : reject error : error ] ;
2017-03-16 12:35:03 +00:00
} else {
resolve ( token ) ;
}
} ] ;
} else {
[ self promiseNoUser : resolve rejecter : reject isError : YES ] ;
}
}
2017-03-14 19:04:16 +00:00
2017-03-17 18:04:13 +00:00
/ * *
signInWithCredential
2017-05-31 14:22:15 +00:00
2017-03-17 18:04:13 +00:00
@ param NSString provider
@ param NSString authToken
@ param NSString authSecret
@ param RCTPromiseResolveBlock resolve
@ param RCTPromiseRejectBlock reject
@ return
* /
2018-01-24 09:46:39 +00:00
RCT_EXPORT _METHOD ( signInWithCredential : ( NSString * ) appDisplayName
provider : ( NSString * ) provider
token : ( NSString * ) authToken
secret : ( NSString * ) authSecret
resolver : ( RCTPromiseResolveBlock ) resolve
rejecter : ( RCTPromiseRejectBlock ) reject ) {
2018-01-03 20:00:38 +00:00
FIRApp * firApp = [ RNFirebaseUtil getApp : appDisplayName ] ;
2017-06-30 16:23:32 +00:00
2017-03-17 18:04:13 +00:00
FIRAuthCredential * credential = [ self getCredentialForProvider : provider token : authToken secret : authSecret ] ;
2017-05-31 14:22:15 +00:00
2017-03-17 18:04:13 +00:00
if ( credential = = nil ) {
2017-03-17 23:33:55 +00:00
return reject ( @ "auth/invalid-credential" , @ "The supplied auth credential is malformed, has expired or is not currently supported." , nil ) ;
2017-03-17 18:04:13 +00:00
}
2017-05-31 14:22:15 +00:00
2017-06-30 16:23:32 +00:00
[ [ FIRAuth authWithApp : firApp ] signInWithCredential : credential completion : ^ ( FIRUser * user , NSError * error ) {
2017-03-17 19:08:51 +00:00
if ( error ) {
2017-03-17 21:41:17 +00:00
[ self promiseRejectAuthException : reject error : error ] ;
2017-03-17 19:08:51 +00:00
} else {
[ self promiseWithUser : resolve rejecter : reject user : user ] ;
2017-03-17 18:04:13 +00:00
}
} ] ;
}
2018-01-24 09:46:39 +00:00
/ * *
signInAndRetrieveDataWithCredential
@ param NSString provider
@ param NSString authToken
@ param NSString authSecret
@ param RCTPromiseResolveBlock resolve
@ param RCTPromiseRejectBlock reject
@ return
* /
RCT_EXPORT _METHOD ( signInAndRetrieveDataWithCredential : ( NSString * ) appDisplayName
provider : ( NSString * ) provider
token : ( NSString * ) authToken
secret : ( NSString * ) authSecret
resolver : ( RCTPromiseResolveBlock ) resolve
rejecter : ( RCTPromiseRejectBlock ) reject ) {
FIRApp * firApp = [ RNFirebaseUtil getApp : appDisplayName ] ;
FIRAuthCredential * credential = [ self getCredentialForProvider : provider token : authToken secret : authSecret ] ;
if ( credential = = nil ) {
return reject ( @ "auth/invalid-credential" , @ "The supplied auth credential is malformed, has expired or is not currently supported." , nil ) ;
}
[ [ FIRAuth authWithApp : firApp ] signInAndRetrieveDataWithCredential : credential completion : ^ ( FIRAuthDataResult * authResult , NSError * error ) {
if ( error ) {
[ self promiseRejectAuthException : reject error : error ] ;
} else {
[ self promiseWithAuthResult : resolve rejecter : reject authResult : authResult ] ;
}
} ] ;
}
2017-07-04 17:22:18 +00:00
/ * *
confirmPasswordReset
@ param NSString code
@ param NSString newPassword
@ param RCTPromiseResolveBlock resolve
@ param RCTPromiseRejectBlock reject
@ return
* /
2017-07-17 19:56:08 +00:00
RCT_EXPORT _METHOD ( confirmPasswordReset :
2018-01-03 20:00:38 +00:00
( NSString * ) appDisplayName
2017-11-07 09:54:38 +00:00
code :
( NSString * ) code
2017-07-17 19:56:08 +00:00
newPassword :
( NSString * ) newPassword
resolver :
( RCTPromiseResolveBlock ) resolve
rejecter :
( RCTPromiseRejectBlock ) reject ) {
2018-01-03 20:00:38 +00:00
FIRApp * firApp = [ RNFirebaseUtil getApp : appDisplayName ] ;
2017-11-07 09:54:38 +00:00
[ [ FIRAuth authWithApp : firApp ] confirmPasswordResetWithCode : code newPassword : newPassword completion : ^ ( NSError * _Nullable error ) {
2017-07-04 17:22:18 +00:00
if ( error ) {
[ self promiseRejectAuthException : reject error : error ] ;
} else {
[ self promiseNoUser : resolve rejecter : reject isError : NO ] ;
}
} ] ;
}
2017-07-05 13:16:35 +00:00
/ * *
* applyActionCode
*
* @ param NSString code
* @ param RCTPromiseResolveBlock resolve
* @ param RCTPromiseRejectBlock reject
* @ return
* /
2017-07-17 19:56:08 +00:00
RCT_EXPORT _METHOD ( applyActionCode :
2018-01-03 20:00:38 +00:00
( NSString * ) appDisplayName
2017-11-07 09:54:38 +00:00
code :
( NSString * ) code
2017-07-17 19:56:08 +00:00
resolver :
( RCTPromiseResolveBlock ) resolve
rejecter :
( RCTPromiseRejectBlock ) reject ) {
2018-01-03 20:00:38 +00:00
FIRApp * firApp = [ RNFirebaseUtil getApp : appDisplayName ] ;
2017-11-07 09:54:38 +00:00
[ [ FIRAuth authWithApp : firApp ] applyActionCode : code completion : ^ ( NSError * _Nullable error ) {
2017-07-05 13:16:35 +00:00
if ( error ) {
[ self promiseRejectAuthException : reject error : error ] ;
} else {
[ self promiseNoUser : resolve rejecter : reject isError : NO ] ;
}
} ] ;
}
2017-07-05 13:56:18 +00:00
/ * *
* checkActionCode
*
* @ param NSString code
* @ param RCTPromiseResolveBlock resolve
* @ param RCTPromiseRejectBlock reject
* @ return
* /
2017-07-17 19:56:08 +00:00
RCT_EXPORT _METHOD ( checkActionCode :
2018-01-03 20:00:38 +00:00
( NSString * ) appDisplayName
2017-11-07 09:54:38 +00:00
code :
( NSString * ) code
2017-07-17 19:56:08 +00:00
resolver :
( RCTPromiseResolveBlock ) resolve
rejecter :
( RCTPromiseRejectBlock ) reject ) {
2018-01-03 20:00:38 +00:00
FIRApp * firApp = [ RNFirebaseUtil getApp : appDisplayName ] ;
2017-11-07 09:54:38 +00:00
[ [ FIRAuth authWithApp : firApp ] checkActionCode : code completion : ^ ( FIRActionCodeInfo * _Nullable info , NSError * _Nullable error ) {
2017-07-05 13:56:18 +00:00
if ( error ) {
2017-07-17 19:56:08 +00:00
[ self promiseRejectAuthException : reject error : error ] ;
2017-07-05 13:56:18 +00:00
} else {
2017-07-12 11:59:35 +00:00
NSString * actionType = @ "ERROR" ;
switch ( info . operation ) {
case FIRActionCodeOperationPasswordReset :
actionType = @ "PASSWORD_RESET" ;
break ;
case FIRActionCodeOperationVerifyEmail :
actionType = @ "VERIFY_EMAIL" ;
break ;
case FIRActionCodeOperationUnknown :
actionType = @ "UNKNOWN" ;
break ;
2017-10-03 15:53:15 +00:00
case FIRActionCodeOperationRecoverEmail :
actionType = @ "RECOVER_EMAIL" ;
break ;
2017-07-12 11:59:35 +00:00
}
2017-07-17 19:56:08 +00:00
NSDictionary * result = @ { @ "data" : @ { @ "email" : [ info dataForKey : FIRActionCodeEmailKey ] , @ "fromEmail" : [ info dataForKey : FIRActionCodeFromEmailKey ] , } , @ "actionType" : actionType , } ;
2017-07-05 13:56:18 +00:00
resolve ( result ) ;
}
} ] ;
}
2017-03-17 18:04:13 +00:00
/ * *
sendPasswordResetEmail
2017-05-31 14:22:15 +00:00
2017-03-17 18:04:13 +00:00
@ param NSString email
@ param RCTPromiseResolveBlock resolve
@ param RCTPromiseRejectBlock reject
@ return
* /
2018-01-03 20:00:38 +00:00
RCT_EXPORT _METHOD ( sendPasswordResetEmail : ( NSString * ) appDisplayName
2017-12-07 12:36:51 +00:00
email : ( NSString * ) email
actionCodeSettings : ( NSDictionary * ) actionCodeSettings
resolver : ( RCTPromiseResolveBlock ) resolve
rejecter : ( RCTPromiseRejectBlock ) reject ) {
2018-01-03 20:00:38 +00:00
FIRApp * firApp = [ RNFirebaseUtil getApp : appDisplayName ] ;
2017-06-30 16:23:32 +00:00
2017-12-07 12:36:51 +00:00
id handler = ^ ( NSError * _Nullable error ) {
2017-03-17 18:04:13 +00:00
if ( error ) {
2017-03-17 21:41:17 +00:00
[ self promiseRejectAuthException : reject error : error ] ;
2017-03-17 18:04:13 +00:00
} else {
[ self promiseNoUser : resolve rejecter : reject isError : NO ] ;
}
2017-12-07 12:36:51 +00:00
} ;
2018-01-03 20:00:38 +00:00
2017-12-07 12:36:51 +00:00
if ( actionCodeSettings ) {
FIRActionCodeSettings * settings = [ self buildActionCodeSettings : actionCodeSettings ] ;
[ [ FIRAuth authWithApp : firApp ] sendPasswordResetWithEmail : email actionCodeSettings : settings completion : handler ] ;
} else {
[ [ FIRAuth authWithApp : firApp ] sendPasswordResetWithEmail : email completion : handler ] ;
}
2017-03-17 18:04:13 +00:00
}
2017-03-14 19:04:16 +00:00
2017-03-17 19:08:51 +00:00
/ * *
2018-01-24 09:46:39 +00:00
signInAndRetrieveDataWithCustomToken
2017-05-31 14:22:15 +00:00
2017-03-17 19:08:51 +00:00
@ param RCTPromiseResolveBlock resolve
@ param RCTPromiseRejectBlock reject
@ return
* /
2018-01-24 09:46:39 +00:00
RCT_EXPORT _METHOD ( signInAndRetrieveDataWithCustomToken : ( NSString * ) appDisplayName
customToken : ( NSString * ) customToken
resolver : ( RCTPromiseResolveBlock ) resolve
rejecter : ( RCTPromiseRejectBlock ) reject ) {
2018-01-03 20:00:38 +00:00
FIRApp * firApp = [ RNFirebaseUtil getApp : appDisplayName ] ;
2017-06-30 16:23:32 +00:00
2018-01-24 09:46:39 +00:00
[ [ FIRAuth authWithApp : firApp ] signInAndRetrieveDataWithCustomToken : customToken completion : ^ ( FIRAuthDataResult * authResult , NSError * error ) {
if ( error ) {
[ self promiseRejectAuthException : reject error : error ] ;
} else {
[ self promiseWithAuthResult : resolve rejecter : reject authResult : authResult ] ;
}
} ] ;
}
/ * *
signInWithCustomToken
@ param RCTPromiseResolveBlock resolve
@ param RCTPromiseRejectBlock reject
@ return
* /
RCT_EXPORT _METHOD ( signInWithCustomToken : ( NSString * ) appDisplayName
customToken : ( NSString * ) customToken
resolver : ( RCTPromiseResolveBlock ) resolve
rejecter : ( RCTPromiseRejectBlock ) reject ) {
FIRApp * firApp = [ RNFirebaseUtil getApp : appDisplayName ] ;
2017-06-30 16:23:32 +00:00
[ [ FIRAuth authWithApp : firApp ] signInWithCustomToken : customToken completion : ^ ( FIRUser * user , NSError * error ) {
2017-03-17 19:08:51 +00:00
if ( error ) {
2017-03-17 21:41:17 +00:00
[ self promiseRejectAuthException : reject error : error ] ;
2017-03-09 15:26:28 +00:00
} else {
2017-03-17 19:08:51 +00:00
[ self promiseWithUser : resolve rejecter : reject user : user ] ;
2017-03-09 15:26:28 +00:00
}
} ] ;
}
2017-08-12 18:07:51 +00:00
/ * *
signInWithPhoneNumber
@ param string phoneNumber
@ param RCTPromiseResolveBlock resolve
@ param RCTPromiseRejectBlock reject
@ return
* /
2018-01-03 20:00:38 +00:00
RCT_EXPORT _METHOD ( signInWithPhoneNumber : ( NSString * ) appDisplayName
2017-08-12 18:07:51 +00:00
phoneNumber : ( NSString * ) phoneNumber
resolver : ( RCTPromiseResolveBlock ) resolve
rejecter : ( RCTPromiseRejectBlock ) reject ) {
2018-01-03 20:00:38 +00:00
FIRApp * firApp = [ RNFirebaseUtil getApp : appDisplayName ] ;
2017-08-12 18:07:51 +00:00
2017-10-03 15:49:03 +00:00
[ [ FIRPhoneAuthProvider providerWithAuth : [ FIRAuth authWithApp : firApp ] ] verifyPhoneNumber : phoneNumber UIDelegate : nil completion : ^ ( NSString * _Nullable verificationID , NSError * _Nullable error ) {
2017-08-12 18:07:51 +00:00
if ( error ) {
[ self promiseRejectAuthException : reject error : error ] ;
} else {
NSUserDefaults * defaults = [ NSUserDefaults standardUserDefaults ] ;
[ defaults setObject : verificationID forKey : @ "authVerificationID" ] ;
resolve ( @ {
@ "verificationId" : verificationID
} ) ;
}
} ] ;
}
2017-10-03 14:41:35 +00:00
/ * *
verifyPhoneNumber
2018-01-03 20:00:38 +00:00
2017-10-03 14:41:35 +00:00
@ param string phoneNumber
@ param RCTPromiseResolveBlock resolve
@ param RCTPromiseRejectBlock reject
@ return
* /
2018-01-03 20:00:38 +00:00
RCT_EXPORT _METHOD ( verifyPhoneNumber : ( NSString * ) appDisplayName
2017-10-03 14:41:35 +00:00
phoneNumber : ( NSString * ) phoneNumber
requestKey : ( NSString * ) requestKey ) {
2018-01-03 20:00:38 +00:00
FIRApp * firApp = [ RNFirebaseUtil getApp : appDisplayName ] ;
2017-10-03 15:49:03 +00:00
[ [ FIRPhoneAuthProvider providerWithAuth : [ FIRAuth authWithApp : firApp ] ] verifyPhoneNumber : phoneNumber UIDelegate : nil completion : ^ ( NSString * _Nullable verificationID , NSError * _Nullable error ) {
2017-10-03 14:41:35 +00:00
if ( error ) {
NSDictionary * jsError = [ self getJSError : ( error ) ] ;
2017-10-26 10:55:07 +00:00
NSDictionary * body = @ {
@ "type" : @ "onVerificationFailed" ,
@ "requestKey" : requestKey ,
@ "state" : @ { @ "error" : jsError } ,
} ;
2018-01-03 20:00:38 +00:00
[ RNFirebaseUtil sendJSEventWithAppName : self app : firApp name : PHONE_AUTH _STATE _CHANGED _EVENT body : body ] ;
2017-10-03 14:41:35 +00:00
} else {
NSUserDefaults * defaults = [ NSUserDefaults standardUserDefaults ] ;
[ defaults setObject : verificationID forKey : @ "authVerificationID" ] ;
2017-10-26 10:55:07 +00:00
NSDictionary * body = @ {
@ "type" : @ "onCodeSent" ,
@ "requestKey" : requestKey ,
@ "state" : @ { @ "verificationId" : verificationID } ,
} ;
2018-01-03 20:00:38 +00:00
[ RNFirebaseUtil sendJSEventWithAppName : self app : firApp name : PHONE_AUTH _STATE _CHANGED _EVENT body : body ] ;
2017-10-03 14:41:35 +00:00
}
} ] ;
}
2018-01-03 20:00:38 +00:00
RCT_EXPORT _METHOD ( _confirmVerificationCode : ( NSString * ) appDisplayName
2017-08-12 18:07:51 +00:00
verificationCode : ( NSString * ) verificationCode
resolver : ( RCTPromiseResolveBlock ) resolve
rejecter : ( RCTPromiseRejectBlock ) reject ) {
2018-01-03 20:00:38 +00:00
FIRApp * firApp = [ RNFirebaseUtil getApp : appDisplayName ] ;
2017-08-12 18:07:51 +00:00
NSUserDefaults * defaults = [ NSUserDefaults standardUserDefaults ] ;
NSString * verificationId = [ defaults stringForKey : @ "authVerificationID" ] ;
FIRAuthCredential * credential = [ [ FIRPhoneAuthProvider provider ] credentialWithVerificationID : verificationId verificationCode : verificationCode ] ;
[ [ FIRAuth authWithApp : firApp ] signInWithCredential : credential completion : ^ ( FIRUser * user , NSError * error ) {
if ( error ) {
[ self promiseRejectAuthException : reject error : error ] ;
} else {
[ self promiseWithUser : resolve rejecter : reject user : user ] ;
}
} ] ;
}
2017-03-17 22:34:35 +00:00
/ * *
2018-01-24 09:46:39 +00:00
linkWithCredential
2017-05-31 14:22:15 +00:00
2017-03-17 22:34:35 +00:00
@ param NSString provider
@ param NSString authToken
@ param NSString authSecret
@ param RCTPromiseResolveBlock resolve
@ param RCTPromiseRejectBlock reject
@ return
* /
2018-01-24 09:46:39 +00:00
RCT_EXPORT _METHOD ( linkWithCredential : ( NSString * ) appDisplayName
provider : ( NSString * ) provider
authToken : ( NSString * ) authToken
authSecret : ( NSString * ) authSecret
resolver : ( RCTPromiseResolveBlock ) resolve
rejecter : ( RCTPromiseRejectBlock ) reject ) {
2018-01-03 20:00:38 +00:00
FIRApp * firApp = [ RNFirebaseUtil getApp : appDisplayName ] ;
2017-03-17 22:34:35 +00:00
FIRAuthCredential * credential = [ self getCredentialForProvider : provider token : authToken secret : authSecret ] ;
2017-05-31 14:22:15 +00:00
2017-03-17 22:34:35 +00:00
if ( credential = = nil ) {
return reject ( @ "auth/invalid-credential" , @ "The supplied auth credential is malformed, has expired or is not currently supported." , nil ) ;
}
2017-05-31 14:22:15 +00:00
2017-06-30 16:23:32 +00:00
FIRUser * user = [ FIRAuth authWithApp : firApp ] . currentUser ;
2017-05-31 14:22:15 +00:00
2017-03-17 22:34:35 +00:00
if ( user ) {
2017-05-25 14:33:41 +00:00
[ user linkWithCredential : credential completion : ^ ( FIRUser * _Nullable _user , NSError * _Nullable error ) {
2017-03-17 22:34:35 +00:00
if ( error ) {
[ self promiseRejectAuthException : reject error : error ] ;
} else {
2017-05-25 14:33:41 +00:00
[ self promiseWithUser : resolve rejecter : reject user : _user ] ;
2017-03-17 22:34:35 +00:00
}
} ] ;
} else {
[ self promiseNoUser : resolve rejecter : reject isError : YES ] ;
}
}
2018-01-24 09:46:39 +00:00
/ * *
linkAndRetrieveDataWithCredential
@ param NSString provider
@ param NSString authToken
@ param NSString authSecret
@ param RCTPromiseResolveBlock resolve
@ param RCTPromiseRejectBlock reject
@ return
* /
RCT_EXPORT _METHOD ( linkAndRetrieveDataWithCredential : ( NSString * ) appDisplayName
provider : ( NSString * ) provider
authToken : ( NSString * ) authToken
authSecret : ( NSString * ) authSecret
resolver : ( RCTPromiseResolveBlock ) resolve
rejecter : ( RCTPromiseRejectBlock ) reject ) {
FIRApp * firApp = [ RNFirebaseUtil getApp : appDisplayName ] ;
FIRAuthCredential * credential = [ self getCredentialForProvider : provider token : authToken secret : authSecret ] ;
if ( credential = = nil ) {
return reject ( @ "auth/invalid-credential" , @ "The supplied auth credential is malformed, has expired or is not currently supported." , nil ) ;
}
FIRUser * user = [ FIRAuth authWithApp : firApp ] . currentUser ;
if ( user ) {
[ user linkAndRetrieveDataWithCredential : credential
completion : ^ ( FIRAuthDataResult * _Nullable authResult , NSError * _Nullable error ) {
if ( error ) {
[ self promiseRejectAuthException : reject error : error ] ;
} else {
[ self promiseWithAuthResult : resolve rejecter : reject authResult : authResult ] ;
}
} ] ;
} else {
[ self promiseNoUser : resolve rejecter : reject isError : YES ] ;
}
}
2017-07-12 15:26:02 +00:00
/ * *
unlink
@ param NSString provider
@ param NSString authToken
@ param NSString authSecret
@ param RCTPromiseResolveBlock resolve
@ param RCTPromiseRejectBlock reject
@ return
* /
2017-07-17 19:56:08 +00:00
RCT_EXPORT _METHOD ( unlink :
2018-01-03 20:00:38 +00:00
( NSString * ) appDisplayName
2017-07-17 19:56:08 +00:00
providerId :
( NSString * ) providerId
resolver :
( RCTPromiseResolveBlock ) resolve
rejecter :
( RCTPromiseRejectBlock ) reject ) {
2018-01-03 20:00:38 +00:00
FIRApp * firApp = [ RNFirebaseUtil getApp : appDisplayName ] ;
2017-07-17 17:26:13 +00:00
FIRUser * user = [ FIRAuth authWithApp : firApp ] . currentUser ;
2017-07-12 15:26:02 +00:00
if ( user ) {
[ user unlinkFromProvider : providerId completion : ^ ( FIRUser * _Nullable _user , NSError * _Nullable error ) {
if ( error ) {
[ self promiseRejectAuthException : reject error : error ] ;
} else {
2017-10-26 14:10:00 +00:00
[ self reloadAndReturnUser : user resolver : resolve rejecter : reject ] ;
2017-07-12 15:26:02 +00:00
}
} ] ;
} else {
[ self promiseNoUser : resolve rejecter : reject isError : YES ] ;
2017-03-17 22:34:35 +00:00
}
}
2017-03-18 00:04:31 +00:00
/ * *
2018-01-18 09:49:11 +00:00
reauthenticateWithCredential
2017-05-31 14:22:15 +00:00
2017-03-18 00:04:31 +00:00
@ param NSString provider
@ param NSString authToken
@ param NSString authSecret
@ param RCTPromiseResolveBlock resolve
@ param RCTPromiseRejectBlock reject
@ return
* /
2018-03-02 09:47:13 +00:00
RCT_EXPORT _METHOD ( reauthenticateWithCredential : ( NSString * ) appDisplayName
provider : ( NSString * ) provider
authToken : ( NSString * ) authToken
authSecret : ( NSString * ) authSecret
resolver : ( RCTPromiseResolveBlock ) resolve
rejecter : ( RCTPromiseRejectBlock ) reject ) {
2018-01-03 20:00:38 +00:00
FIRApp * firApp = [ RNFirebaseUtil getApp : appDisplayName ] ;
2017-06-30 16:23:32 +00:00
2017-03-18 00:04:31 +00:00
FIRAuthCredential * credential = [ self getCredentialForProvider : provider token : authToken secret : authSecret ] ;
2017-05-31 14:22:15 +00:00
2017-03-18 00:04:31 +00:00
if ( credential = = nil ) {
return reject ( @ "auth/invalid-credential" , @ "The supplied auth credential is malformed, has expired or is not currently supported." , nil ) ;
}
2017-05-31 14:22:15 +00:00
2017-06-30 16:23:32 +00:00
FIRUser * user = [ FIRAuth authWithApp : firApp ] . currentUser ;
2017-05-31 14:22:15 +00:00
2017-03-18 00:04:31 +00:00
if ( user ) {
[ user reauthenticateWithCredential : credential completion : ^ ( NSError * _Nullable error ) {
if ( error ) {
[ self promiseRejectAuthException : reject error : error ] ;
} else {
2017-06-30 16:23:32 +00:00
FIRUser * userAfterAuth = [ FIRAuth authWithApp : firApp ] . currentUser ;
2017-03-18 00:04:31 +00:00
[ self promiseWithUser : resolve rejecter : reject user : userAfterAuth ] ;
}
} ] ;
} else {
[ self promiseNoUser : resolve rejecter : reject isError : YES ] ;
}
}
2018-03-02 09:47:13 +00:00
/ * *
reauthenticateAndRetrieveDataWithCredential
@ param NSString provider
@ param NSString authToken
@ param NSString authSecret
@ param RCTPromiseResolveBlock resolve
@ param RCTPromiseRejectBlock reject
@ return
* /
RCT_EXPORT _METHOD ( reauthenticateAndRetrieveDataWithCredential : ( NSString * ) appDisplayName
provider : ( NSString * ) provider
authToken : ( NSString * ) authToken
authSecret : ( NSString * ) authSecret
resolver : ( RCTPromiseResolveBlock ) resolve
rejecter : ( RCTPromiseRejectBlock ) reject ) {
FIRApp * firApp = [ RNFirebaseUtil getApp : appDisplayName ] ;
FIRAuthCredential * credential = [ self getCredentialForProvider : provider token : authToken secret : authSecret ] ;
if ( credential = = nil ) {
return reject ( @ "auth/invalid-credential" , @ "The supplied auth credential is malformed, has expired or is not currently supported." , nil ) ;
}
FIRUser * user = [ FIRAuth authWithApp : firApp ] . currentUser ;
if ( user ) {
[ user reauthenticateAndRetrieveDataWithCredential : credential completion : ^ ( FIRAuthDataResult * _Nullable authResult , NSError * _Nullable error ) {
if ( error ) {
[ self promiseRejectAuthException : reject error : error ] ;
} else {
[ self promiseWithAuthResult : resolve rejecter : reject authResult : authResult ] ;
}
} ] ;
} else {
[ self promiseNoUser : resolve rejecter : reject isError : YES ] ;
}
}
2017-05-25 13:45:03 +00:00
/ * *
fetchProvidersForEmail
@ param NSString email
@ param RCTPromiseResolveBlock resolve
@ param RCTPromiseRejectBlock reject
@ return
* /
2017-07-17 19:56:08 +00:00
RCT_EXPORT _METHOD ( fetchProvidersForEmail :
2018-01-03 20:00:38 +00:00
( NSString * ) appDisplayName
2017-07-17 19:56:08 +00:00
email :
( NSString * ) email
2017-06-29 16:24:34 +00:00
resolver :
( RCTPromiseResolveBlock ) resolve
rejecter :
( RCTPromiseRejectBlock ) reject ) {
2018-01-03 20:00:38 +00:00
FIRApp * firApp = [ RNFirebaseUtil getApp : appDisplayName ] ;
2017-06-30 16:23:32 +00:00
[ [ FIRAuth authWithApp : firApp ] fetchProvidersForEmail : email completion : ^ ( NSArray < NSString * > * _Nullable providers , NSError * _Nullable error ) {
2017-05-25 13:45:03 +00:00
if ( error ) {
[ self promiseRejectAuthException : reject error : error ] ;
} else if ( ! providers ) {
NSMutableArray * emptyResponse = [ [ NSMutableArray alloc ] init ] ;
resolve ( emptyResponse ) ;
} else {
resolve ( providers ) ;
}
} ] ;
}
2017-03-17 22:34:35 +00:00
/ * *
getCredentialForProvider
2017-05-31 14:22:15 +00:00
2017-10-03 14:41:35 +00:00
@ param provider string
@ param authToken string
@ param authTokenSecret string
2017-03-17 22:34:35 +00:00
@ return FIRAuthCredential
* /
- ( FIRAuthCredential * ) getCredentialForProvider : ( NSString * ) provider token : ( NSString * ) authToken secret : ( NSString * ) authTokenSecret {
FIRAuthCredential * credential ;
2017-05-31 14:22:15 +00:00
2017-10-16 10:12:40 +00:00
if ( [ provider compare : @ "twitter.com" options : NSCaseInsensitiveSearch ] = = NSOrderedSame ) {
2017-03-17 22:34:35 +00:00
credential = [ FIRTwitterAuthProvider credentialWithToken : authToken secret : authTokenSecret ] ;
2017-10-16 10:12:40 +00:00
} else if ( [ provider compare : @ "facebook.com" options : NSCaseInsensitiveSearch ] = = NSOrderedSame ) {
2017-03-17 22:34:35 +00:00
credential = [ FIRFacebookAuthProvider credentialWithAccessToken : authToken ] ;
2017-10-16 10:12:40 +00:00
} else if ( [ provider compare : @ "google.com" options : NSCaseInsensitiveSearch ] = = NSOrderedSame ) {
2017-03-17 22:34:35 +00:00
credential = [ FIRGoogleAuthProvider credentialWithIDToken : authToken accessToken : authTokenSecret ] ;
} else if ( [ provider compare : @ "password" options : NSCaseInsensitiveSearch ] = = NSOrderedSame ) {
2017-07-30 06:34:41 +00:00
credential = [ FIREmailAuthProvider credentialWithEmail : authToken password : authTokenSecret ] ;
2017-10-16 10:12:40 +00:00
} else if ( [ provider compare : @ "github.com" options : NSCaseInsensitiveSearch ] = = NSOrderedSame ) {
2017-03-17 22:34:35 +00:00
credential = [ FIRGitHubAuthProvider credentialWithToken : authToken ] ;
2017-09-01 07:47:42 +00:00
} else if ( [ provider compare : @ "phone" options : NSCaseInsensitiveSearch ] = = NSOrderedSame ) {
credential = [ [ FIRPhoneAuthProvider provider ] credentialWithVerificationID : authToken verificationCode : authTokenSecret ] ;
2018-01-24 15:21:52 +00:00
} else if ( [ provider compare : @ "oauth" options : NSCaseInsensitiveSearch ] = = NSOrderedSame ) {
credential = [ FIROAuthProvider credentialWithProviderID : @ "oauth" IDToken : authToken accessToken : authTokenSecret ] ;
2017-03-17 22:34:35 +00:00
} else {
NSLog ( @ "Provider not yet handled: %@" , provider ) ;
}
2017-05-31 14:22:15 +00:00
2017-03-17 22:34:35 +00:00
return credential ;
}
2017-11-30 10:17:04 +00:00
/ * *
setLanguageCode
@ param NSString code
@ return
* /
RCT_EXPORT _METHOD ( setLanguageCode :
2018-01-08 10:07:15 +00:00
( NSString * ) appDisplayName
2017-11-30 10:17:04 +00:00
code :
( NSString * ) code ) {
2018-01-08 10:07:15 +00:00
FIRApp * firApp = [ RNFirebaseUtil getApp : appDisplayName ] ;
2017-11-30 10:17:04 +00:00
[ FIRAuth authWithApp : firApp ] . languageCode = code ;
}
/ * *
useDeviceLanguage
@ param NSString code
@ return
* /
2018-01-24 12:20:06 +00:00
RCT_EXPORT _METHOD ( useDeviceLanguage : ( NSString * ) appDisplayName ) {
2018-01-08 10:07:15 +00:00
FIRApp * firApp = [ RNFirebaseUtil getApp : appDisplayName ] ;
2017-11-30 10:17:04 +00:00
2018-01-24 12:20:06 +00:00
[ [ FIRAuth authWithApp : firApp ] useAppLanguage ] ;
}
RCT_EXPORT _METHOD ( verifyPasswordResetCode : ( NSString * ) appDisplayName
code : ( NSString * ) code
resolver : ( RCTPromiseResolveBlock ) resolve
rejecter : ( RCTPromiseRejectBlock ) reject ) {
FIRApp * firApp = [ RNFirebaseUtil getApp : appDisplayName ] ;
[ [ FIRAuth authWithApp : firApp ] verifyPasswordResetCode : code completion : ^ ( NSString * _Nullable email , NSError * _Nullable error ) {
if ( error ) {
[ self promiseRejectAuthException : reject error : error ] ;
} else {
resolve ( email ) ;
}
} ] ;
2017-11-30 10:17:04 +00:00
}
2017-10-26 14:10:00 +00:00
// This is here to protect against bugs in the iOS SDK which don ' t
// correctly refresh the user object when performing certain operations
- ( void ) reloadAndReturnUser : ( FIRUser * ) user
resolver : ( RCTPromiseResolveBlock ) resolve
rejecter : ( RCTPromiseRejectBlock ) reject {
[ user reloadWithCompletion : ^ ( NSError * _Nullable error ) {
if ( error ) {
[ self promiseRejectAuthException : reject error : error ] ;
} else {
[ self promiseWithUser : resolve rejecter : reject user : user ] ;
}
} ] ;
}
2017-03-17 22:34:35 +00:00
2017-03-14 19:04:16 +00:00
/ * *
Resolve or reject a promise based on isError value
2017-05-31 14:22:15 +00:00
2017-03-14 19:04:16 +00:00
@ param resolve RCTPromiseResolveBlock
@ param reject RCTPromiseRejectBlock
@ param isError BOOL
* /
2017-06-29 16:24:34 +00:00
- ( void ) promiseNoUser : ( RCTPromiseResolveBlock ) resolve rejecter : ( RCTPromiseRejectBlock ) reject isError : ( BOOL ) isError {
2017-03-14 19:04:16 +00:00
if ( isError ) {
2017-05-25 13:45:03 +00:00
reject ( @ "auth/no-current-user" , @ "No user currently signed in." , nil ) ;
2017-03-14 19:04:16 +00:00
} else {
resolve ( [ NSNull null ] ) ;
}
}
2017-03-17 19:08:51 +00:00
/ * *
Reject a promise with an auth exception
2017-05-31 14:22:15 +00:00
2017-03-17 19:08:51 +00:00
@ param reject RCTPromiseRejectBlock
@ param error NSError
* /
2017-06-29 16:24:34 +00:00
- ( void ) promiseRejectAuthException : ( RCTPromiseRejectBlock ) reject error : ( NSError * ) error {
2017-10-03 14:41:35 +00:00
NSDictionary * jsError = [ self getJSError : ( error ) ] ;
reject ( [ jsError valueForKey : @ "code" ] , [ jsError valueForKey : @ "message" ] , error ) ;
}
/ * *
Reject a promise with an auth exception
2018-01-03 20:00:38 +00:00
2017-10-03 14:41:35 +00:00
@ param error NSError
* /
- ( NSDictionary * ) getJSError : ( NSError * ) error {
2017-03-17 21:41:17 +00:00
NSString * code = @ "auth/unknown" ;
NSString * message = [ error localizedDescription ] ;
2017-10-03 14:41:35 +00:00
NSString * nativeErrorMessage = [ error localizedDescription ] ;
2018-01-03 20:00:38 +00:00
2017-03-17 21:41:17 +00:00
switch ( error . code ) {
case FIRAuthErrorCodeInvalidCustomToken :
code = @ "auth/invalid-custom-token" ;
message = @ "The custom token format is incorrect. Please check the documentation." ;
break ;
case FIRAuthErrorCodeCustomTokenMismatch :
code = @ "auth/custom-token-mismatch" ;
message = @ "The custom token corresponds to a different audience." ;
break ;
case FIRAuthErrorCodeInvalidCredential :
code = @ "auth/invalid-credential" ;
message = @ "The supplied auth credential is malformed or has expired." ;
break ;
case FIRAuthErrorCodeInvalidEmail :
code = @ "auth/invalid-email" ;
message = @ "The email address is badly formatted." ;
break ;
case FIRAuthErrorCodeWrongPassword :
code = @ "auth/wrong-password" ;
message = @ "The password is invalid or the user does not have a password." ;
break ;
case FIRAuthErrorCodeUserMismatch :
code = @ "auth/user-mismatch" ;
message = @ "The supplied credentials do not correspond to the previously signed in user." ;
break ;
case FIRAuthErrorCodeRequiresRecentLogin :
code = @ "auth/requires-recent-login" ;
message = @ "This operation is sensitive and requires recent authentication. Log in again before retrying this request." ;
break ;
case FIRAuthErrorCodeAccountExistsWithDifferentCredential :
code = @ "auth/account-exists-with-different-credential" ;
message = @ "An account already exists with the same email address but different sign-in credentials. Sign in using a provider associated with this email address." ;
break ;
case FIRAuthErrorCodeEmailAlreadyInUse :
code = @ "auth/email-already-in-use" ;
message = @ "The email address is already in use by another account." ;
break ;
case FIRAuthErrorCodeCredentialAlreadyInUse :
code = @ "auth/credential-already-in-use" ;
message = @ "This credential is already associated with a different user account." ;
break ;
case FIRAuthErrorCodeUserDisabled :
code = @ "auth/user-disabled" ;
message = @ "The user account has been disabled by an administrator." ;
break ;
case FIRAuthErrorCodeUserTokenExpired :
code = @ "auth/user-token-expired" ;
message = @ "The user's credential is no longer valid. The user must sign in again." ;
break ;
case FIRAuthErrorCodeUserNotFound :
code = @ "auth/user-not-found" ;
message = @ "There is no user record corresponding to this identifier. The user may have been deleted." ;
break ;
case FIRAuthErrorCodeInvalidUserToken :
code = @ "auth/invalid-user-token" ;
message = @ "The user's credential is no longer valid. The user must sign in again." ;
break ;
case FIRAuthErrorCodeWeakPassword :
code = @ "auth/weak-password" ;
message = @ "The given password is invalid." ;
break ;
case FIRAuthErrorCodeOperationNotAllowed :
code = @ "auth/operation-not-allowed" ;
message = @ "This operation is not allowed. You must enable this service in the console." ;
break ;
case FIRAuthErrorCodeNetworkError :
code = @ "auth/network-error" ;
message = @ "A network error has occurred, please try again." ;
break ;
case FIRAuthErrorCodeInternalError :
code = @ "auth/internal-error" ;
message = @ "An internal error has occurred, please try again." ;
break ;
2018-01-03 20:00:38 +00:00
2017-03-17 22:00:13 +00:00
// unsure of the below codes so leaving them as the default error message
2017-03-17 21:41:17 +00:00
case FIRAuthErrorCodeTooManyRequests :
code = @ "auth/too-many-requests" ;
break ;
case FIRAuthErrorCodeProviderAlreadyLinked :
code = @ "auth/provider-already-linked" ;
break ;
case FIRAuthErrorCodeNoSuchProvider :
code = @ "auth/no-such-provider" ;
break ;
case FIRAuthErrorCodeInvalidAPIKey :
code = @ "auth/invalid-api-key" ;
break ;
case FIRAuthErrorCodeAppNotAuthorized :
code = @ "auth/app-not-authorised" ;
break ;
case FIRAuthErrorCodeExpiredActionCode :
code = @ "auth/expired-action-code" ;
break ;
case FIRAuthErrorCodeInvalidMessagePayload :
code = @ "auth/invalid-message-payload" ;
break ;
case FIRAuthErrorCodeInvalidSender :
code = @ "auth/invalid-sender" ;
break ;
case FIRAuthErrorCodeInvalidRecipientEmail :
code = @ "auth/invalid-recipient-email" ;
break ;
case FIRAuthErrorCodeKeychainError :
code = @ "auth/keychain-error" ;
break ;
default :
break ;
}
2018-01-03 20:00:38 +00:00
2017-10-03 14:41:35 +00:00
return @ {
@ "code" : code ,
@ "message" : message ,
@ "nativeErrorMessage" : nativeErrorMessage ,
} ;
2017-03-17 19:08:51 +00:00
}
2017-10-03 14:41:35 +00:00
2017-03-14 19:04:16 +00:00
/ * *
Resolve or reject a promise based on FIRUser value existance
2017-05-31 14:22:15 +00:00
2017-03-14 19:04:16 +00:00
@ param resolve RCTPromiseResolveBlock
@ param reject RCTPromiseRejectBlock
@ param user FIRUser
* /
2017-06-29 16:24:34 +00:00
- ( void ) promiseWithUser : ( RCTPromiseResolveBlock ) resolve rejecter : ( RCTPromiseRejectBlock ) reject user : ( FIRUser * ) user {
2017-03-14 19:04:16 +00:00
if ( user ) {
NSDictionary * userDict = [ self firebaseUserToDict : user ] ;
resolve ( userDict ) ;
} else {
[ self promiseNoUser : resolve rejecter : reject isError : YES ] ;
}
2017-05-31 14:22:15 +00:00
2017-03-14 19:04:16 +00:00
}
2018-01-24 09:46:39 +00:00
/ * *
Resolve or reject a promise based on FIRAuthResult value existance
@ param resolve RCTPromiseResolveBlock
@ param reject RCTPromiseRejectBlock
@ param authResult FIRAuthDataResult
* /
- ( void ) promiseWithAuthResult : ( RCTPromiseResolveBlock ) resolve rejecter : ( RCTPromiseRejectBlock ) reject authResult : ( FIRAuthDataResult * ) authResult {
if ( authResult && authResult . user ) {
NSDictionary * userDict = [ self firebaseUserToDict : authResult . user ] ;
NSDictionary * authResultDict = @ {
@ "additionalUserInfo" : authResult . additionalUserInfo ? @ {
@ "isNewUser" : @ ( authResult . additionalUserInfo . isNewUser ) ,
@ "profile" : authResult . additionalUserInfo . profile ? authResult . additionalUserInfo . profile : [ NSNull null ] ,
@ "providerId" : authResult . additionalUserInfo . providerID ? authResult . additionalUserInfo . providerID : [ NSNull null ] ,
@ "username" : authResult . additionalUserInfo . username ? authResult . additionalUserInfo . username : [ NSNull null ]
} : [ NSNull null ] ,
@ "user" : userDict
} ;
resolve ( authResultDict ) ;
} else {
[ self promiseNoUser : resolve rejecter : reject isError : YES ] ;
}
}
2017-05-12 12:58:16 +00:00
/ * *
2017-05-12 12:13:17 +00:00
Converts an array of FIRUserInfo instances into the correct format to match the web sdk
2017-05-31 14:22:15 +00:00
2017-05-12 12:13:17 +00:00
@ param providerData FIRUser . providerData
@ return NSArray
* /
2017-06-29 16:24:34 +00:00
- ( NSArray < NSObject * > * ) convertProviderData : ( NSArray < id < FIRUserInfo > > * ) providerData {
2017-05-12 12:13:17 +00:00
NSMutableArray * output = [ NSMutableArray array ] ;
2017-05-31 14:22:15 +00:00
2017-06-29 16:24:34 +00:00
for ( id < FIRUserInfo > userInfo in providerData ) {
2017-05-13 12:08:43 +00:00
NSMutableDictionary * pData = [ NSMutableDictionary dictionary ] ;
2017-05-31 14:22:15 +00:00
2017-05-13 00:46:27 +00:00
if ( userInfo . providerID ! = nil ) {
2017-06-29 16:24:34 +00:00
[ pData setValue : userInfo . providerID forKey : @ "providerId" ] ;
2017-05-13 00:46:27 +00:00
}
2017-05-31 14:22:15 +00:00
2017-05-13 00:46:27 +00:00
if ( userInfo . uid ! = nil ) {
2017-06-29 16:24:34 +00:00
[ pData setValue : userInfo . uid forKey : @ "uid" ] ;
2017-05-13 00:46:27 +00:00
}
2017-05-31 14:22:15 +00:00
2017-05-13 00:46:27 +00:00
if ( userInfo . displayName ! = nil ) {
2017-06-29 16:24:34 +00:00
[ pData setValue : userInfo . displayName forKey : @ "displayName" ] ;
2017-05-13 00:46:27 +00:00
}
2017-05-31 14:22:15 +00:00
2017-05-13 00:46:27 +00:00
if ( userInfo . photoURL ! = nil ) {
2017-06-29 16:24:34 +00:00
[ pData setValue : [ userInfo . photoURL absoluteString ] forKey : @ "photoURL" ] ;
2017-05-13 00:46:27 +00:00
}
2017-05-31 14:22:15 +00:00
2017-05-13 00:46:27 +00:00
if ( userInfo . email ! = nil ) {
2017-06-29 16:24:34 +00:00
[ pData setValue : userInfo . email forKey : @ "email" ] ;
2017-05-13 00:46:27 +00:00
}
2017-05-31 14:22:15 +00:00
2017-08-12 18:07:51 +00:00
if ( userInfo . phoneNumber ! = nil ) {
[ pData setValue : userInfo . phoneNumber forKey : @ "phoneNumber" ] ;
}
2017-05-13 00:46:27 +00:00
[ output addObject : pData ] ;
2017-05-12 12:13:17 +00:00
}
2017-05-31 14:22:15 +00:00
2017-05-12 12:13:17 +00:00
return output ;
}
2017-11-30 12:08:12 +00:00
/ * *
* React native constant exports - exports native firebase apps mainly
* @ return NSDictionary
* /
- ( NSDictionary * ) constantsToExport {
NSMutableDictionary * constants = [ NSMutableDictionary new ] ;
NSDictionary * firApps = [ FIRApp allApps ] ;
NSMutableDictionary * appLanguage = [ NSMutableDictionary new ] ;
for ( id key in firApps ) {
FIRApp * firApp = firApps [ key ] ;
appLanguage [ firApp . name ] = [ FIRAuth authWithApp : firApp ] . languageCode ;
}
constants [ @ "APP_LANGUAGE" ] = appLanguage ;
return constants ;
}
2017-03-14 19:04:16 +00:00
/ * *
Converts a FIRUser instance into a dictionary to send via RNBridge
2017-05-31 14:22:15 +00:00
2017-03-14 19:04:16 +00:00
@ param user FIRUser
@ return NSDictionary
* /
2018-01-19 16:19:08 +00:00
- ( NSDictionary * ) firebaseUserToDict : ( FIRUser * ) user {
return @ {
@ "displayName" : user . displayName ? user . displayName : [ NSNull null ] ,
@ "email" : user . email ? user . email : [ NSNull null ] ,
@ "emailVerified" : @ ( user . emailVerified ) ,
@ "isAnonymous" : @ ( user . anonymous ) ,
@ "metadata" : @ {
@ "creationTime" : user . metadata . creationDate ? @ ( round ( [ user . metadata . creationDate timeIntervalSince1970 ] * 1000.0 ) ) : [ NSNull null ] ,
@ "lastSignInTime" : user . metadata . lastSignInDate ? @ ( round ( [ user . metadata . lastSignInDate timeIntervalSince1970 ] * 1000.0 ) ) : [ NSNull null ] ,
} ,
@ "phoneNumber" : user . phoneNumber ? user . phoneNumber : [ NSNull null ] ,
@ "photoURL" : user . photoURL ? [ user . photoURL absoluteString ] : [ NSNull null ] ,
@ "providerData" : [ self convertProviderData : user . providerData ] ,
@ "providerId" : [ user . providerID lowercaseString ] ,
@ "refreshToken" : user . refreshToken ,
@ "uid" : user . uid
} ;
2017-03-14 19:04:16 +00:00
}
2017-03-09 15:26:28 +00:00
2017-12-07 12:36:51 +00:00
- ( FIRActionCodeSettings * ) buildActionCodeSettings : ( NSDictionary * ) actionCodeSettings {
FIRActionCodeSettings * settings = [ [ FIRActionCodeSettings alloc ] init ] ;
NSDictionary * android = actionCodeSettings [ @ "android" ] ;
BOOL handleCodeInApp = actionCodeSettings [ @ "handleCodeInApp" ] ;
NSDictionary * ios = actionCodeSettings [ @ "iOS" ] ;
NSString * url = actionCodeSettings [ @ "url" ] ;
if ( android ) {
BOOL installApp = android [ @ "installApp" ] ;
NSString * minimumVersion = android [ @ "minimumVersion" ] ;
NSString * packageName = android [ @ "packageName" ] ;
[ settings setAndroidPackageName : packageName installIfNotAvailable : installApp minimumVersion : minimumVersion ] ;
}
if ( handleCodeInApp ) {
[ settings setHandleCodeInApp : handleCodeInApp ] ;
}
if ( ios && ios [ @ "bundleId" ] ) {
[ settings setIOSBundleID : ios [ @ "bundleId" ] ] ;
}
if ( url ) {
[ settings setURL : [ NSURL URLWithString : url ] ] ;
}
return settings ;
}
2017-03-17 19:08:51 +00:00
- ( NSArray < NSString * > * ) supportedEvents {
2018-01-24 09:46:39 +00:00
return @ [ AUTH_STATE _CHANGED _EVENT , AUTH_ID _TOKEN _CHANGED _EVENT , PHONE_AUTH _STATE _CHANGED _EVENT ] ;
2017-03-17 19:08:51 +00:00
}
2017-10-12 08:18:01 +00:00
+ ( BOOL ) requiresMainQueueSetup
{
return YES ;
}
2017-03-09 15:26:28 +00:00
@ end
2017-05-25 14:33:41 +00:00
# else
@ implementation RNFirebaseAuth
@ end
# endif