@@ -45,9 +45,9 @@ actual class FirebaseAuth internal constructor(val ios: FIRAuth) {
45
45
actual suspend fun confirmPasswordReset (code : String , newPassword : String ) = ios.await { confirmPasswordResetWithCode(code, newPassword, it) }.run { Unit }
46
46
47
47
actual suspend fun createUserWithEmailAndPassword (email : String , password : String ) =
48
- AuthResult (ios.awaitExpectedResult { createUserWithEmail(email = email, password = password, completion = it) })
48
+ AuthResult (ios.awaitResult { createUserWithEmail(email = email, password = password, completion = it) })
49
49
50
- actual suspend fun fetchSignInMethodsForEmail (email : String ) = ios.awaitResult { fetchSignInMethodsForEmail(email, it) }.orEmpty()
50
+ actual suspend fun fetchSignInMethodsForEmail (email : String ) = ios.awaitResult { fetchSignInMethodsForEmail(email, it) } as List < String >
51
51
52
52
actual suspend fun sendPasswordResetEmail (email : String , actionCodeSettings : ActionCodeSettings ? ) {
53
53
ios.await { actionCodeSettings?.let { actionSettings -> sendPasswordResetWithEmail(email, actionSettings.toIos(), it) } ? : sendPasswordResetWithEmail(email = email, completion = it) }
@@ -56,24 +56,24 @@ actual class FirebaseAuth internal constructor(val ios: FIRAuth) {
56
56
actual suspend fun sendSignInLinkToEmail (email : String , actionCodeSettings : ActionCodeSettings ) = ios.await { sendSignInLinkToEmail(email, actionCodeSettings.toIos(), it) }.run { Unit }
57
57
58
58
actual suspend fun signInWithEmailAndPassword (email : String , password : String ) =
59
- AuthResult (ios.awaitExpectedResult { signInWithEmail(email = email, password = password, completion = it) })
59
+ AuthResult (ios.awaitResult { signInWithEmail(email = email, password = password, completion = it) })
60
60
61
61
actual suspend fun signInWithCustomToken (token : String ) =
62
- AuthResult (ios.awaitExpectedResult { signInWithCustomToken(token, it) })
62
+ AuthResult (ios.awaitResult { signInWithCustomToken(token, it) })
63
63
64
64
actual suspend fun signInAnonymously () =
65
- AuthResult (ios.awaitExpectedResult { signInAnonymouslyWithCompletion(it) })
65
+ AuthResult (ios.awaitResult { signInAnonymouslyWithCompletion(it) })
66
66
67
67
actual suspend fun signInWithCredential (authCredential : AuthCredential ) =
68
- AuthResult (ios.awaitExpectedResult { signInWithCredential(authCredential.ios, it) })
68
+ AuthResult (ios.awaitResult { signInWithCredential(authCredential.ios, it) })
69
69
70
70
actual suspend fun signOut () = ios.throwError { signOut(it) }.run { Unit }
71
71
72
72
actual suspend fun updateCurrentUser (user : FirebaseUser ) = ios.await { updateCurrentUser(user.ios, it) }.run { Unit }
73
- actual suspend fun verifyPasswordResetCode (code : String ): String = ios.awaitExpectedResult { verifyPasswordResetCode(code, it) }
73
+ actual suspend fun verifyPasswordResetCode (code : String ): String = ios.awaitResult { verifyPasswordResetCode(code, it) }
74
74
75
75
actual suspend fun <T : ActionCodeResult > checkActionCode (code : String ): T {
76
- val result = ios.awaitExpectedResult { checkActionCode(code, it) }
76
+ val result = ios.awaitResult { checkActionCode(code, it) }
77
77
@Suppress(" UNCHECKED_CAST" )
78
78
return when (result.operation) {
79
79
FIRActionCodeOperationUnknown -> Error
@@ -93,7 +93,7 @@ actual class AuthResult internal constructor(val ios: FIRAuthDataResult) {
93
93
get() = FirebaseUser (ios.user)
94
94
}
95
95
96
- internal fun ActionCodeSettings.toIos () = FIRActionCodeSettings ().let {
96
+ internal fun ActionCodeSettings.toIos () = FIRActionCodeSettings ().also {
97
97
it.URL = NSURL .URLWithString (url)
98
98
androidPackageName?.run { it.setAndroidPackageName(androidPackageName, installIfNotAvailable, minimumVersion) }
99
99
it.dynamicLinkDomain = dynamicLinkDomain
@@ -127,41 +127,13 @@ internal fun <T, R> T.throwError(block: T.(errorPointer: CPointer<ObjCObjectVar<
127
127
}
128
128
}
129
129
130
- internal suspend fun <T , R > T.awaitResult (function : T .(callback: (R ? , NSError ? ) -> Unit ) -> Unit ): R ? {
131
- val job = CompletableDeferred <R ?>()
132
- function { result, error ->
133
- if (error != null ) {
134
- job.completeExceptionally(error.toException())
135
- } else {
136
- job.complete(result)
137
- }
138
- }
139
- return job.await()
140
- }
141
-
142
- internal suspend fun <T , R > T.awaitResult (default : R , function : T .(callback: (R ? , NSError ? ) -> Unit ) -> Unit ): R {
130
+ internal suspend fun <T , R > T.awaitResult (function : T .(callback: (R , NSError ? ) -> Unit ) -> Unit ): R {
143
131
val job = CompletableDeferred <R >()
144
132
function { result, error ->
145
- if (result ! = null ) {
133
+ if (error = = null ) {
146
134
job.complete(result)
147
- } else if (error != null ) {
148
- job.completeExceptionally(error.toException())
149
135
} else {
150
- job.complete(default)
151
- }
152
- }
153
- return job.await()
154
- }
155
-
156
- internal suspend fun <T , R > T.awaitExpectedResult (function : T .(callback: (R ? , NSError ? ) -> Unit ) -> Unit ): R {
157
- val job = CompletableDeferred <R >()
158
- function { result, error ->
159
- if (result != null ) {
160
- job.complete(result)
161
- } else if (error != null ) {
162
136
job.completeExceptionally(error.toException())
163
- } else {
164
- job.completeExceptionally(UnexpectedNullResultException ())
165
137
}
166
138
}
167
139
return job.await()
0 commit comments