@@ -38,13 +38,12 @@ actual class FirebaseAuth internal constructor(val js: firebase.auth.Auth) {
38
38
set(value) { js.languageCode = value }
39
39
40
40
actual suspend fun applyActionCode (code : String ) = rethrow { js.applyActionCode(code).await() }
41
- actual suspend fun checkActionCode (code : String ): ActionCodeResult = rethrow { ActionCodeResult (js.checkActionCode(code).await()) }
42
41
actual suspend fun confirmPasswordReset (code : String , newPassword : String ) = rethrow { js.confirmPasswordReset(code, newPassword).await() }
43
42
44
43
actual suspend fun createUserWithEmailAndPassword (email : String , password : String ) =
45
44
rethrow { AuthResult (js.createUserWithEmailAndPassword(email, password).await()) }
46
45
47
- actual suspend fun fetchSignInMethodsForEmail (email : String ): SignInMethodQueryResult = rethrow { SignInMethodQueryResult ( js.fetchSignInMethodsForEmail(email).await().asList() ) }
46
+ actual suspend fun fetchSignInMethodsForEmail (email : String ): List < String > = rethrow { js.fetchSignInMethodsForEmail(email).await().asList() }
48
47
49
48
actual suspend fun sendPasswordResetEmail (email : String , actionCodeSettings : ActionCodeSettings ? ) =
50
49
rethrow { js.sendPasswordResetEmail(email, actionCodeSettings?.toJson()).await() }
@@ -55,63 +54,49 @@ actual class FirebaseAuth internal constructor(val js: firebase.auth.Auth) {
55
54
actual suspend fun signInWithEmailAndPassword (email : String , password : String ) =
56
55
rethrow { AuthResult (js.signInWithEmailAndPassword(email, password).await()) }
57
56
58
- actual suspend fun signInWithCustomToken (token : String )
59
- = rethrow { AuthResult (js.signInWithCustomToken(token).await()) }
57
+ actual suspend fun signInWithCustomToken (token : String ) =
58
+ rethrow { AuthResult (js.signInWithCustomToken(token).await()) }
60
59
61
- actual suspend fun signInAnonymously ()
62
- = rethrow { AuthResult (js.signInAnonymously().await()) }
60
+ actual suspend fun signInAnonymously () =
61
+ rethrow { AuthResult (js.signInAnonymously().await()) }
63
62
64
63
actual suspend fun signInWithCredential (authCredential : AuthCredential ) =
65
64
rethrow { AuthResult (js.signInWithCredential(authCredential.js).await()) }
66
65
67
66
actual suspend fun signOut () = rethrow { js.signOut().await() }
68
67
69
68
actual suspend fun updateCurrentUser (user : FirebaseUser ) =
70
- rethrow {
71
- js.updateCurrentUser(user.js).await()
72
- }
73
- actual suspend fun verifyPasswordResetCode (code : String ): String =
74
- rethrow {
75
- js.verifyPasswordResetCode(code).await()
76
- }
69
+ rethrow { js.updateCurrentUser(user.js).await() }
77
70
71
+ actual suspend fun verifyPasswordResetCode (code : String ): String =
72
+ rethrow { js.verifyPasswordResetCode(code).await() }
73
+
74
+ actual suspend fun <T : ActionCodeResult > checkActionCode (code : String ): T = rethrow {
75
+ val result = js.checkActionCode(code).await()
76
+ @Suppress(" UNCHECKED_CAST" )
77
+ return when (result.operation) {
78
+ " EMAIL_SIGNIN" -> ActionCodeResult .SignInWithEmailLink
79
+ " VERIFY_EMAIL" -> ActionCodeResult .VerifyEmail (result.data.email!! )
80
+ " PASSWORD_RESET" -> ActionCodeResult .PasswordReset (result.data.email!! )
81
+ " RECOVER_EMAIL" -> ActionCodeResult .RecoverEmail (result.data.email!! , result.data.previousEmail!! )
82
+ " VERIFY_AND_CHANGE_EMAIL" -> ActionCodeResult .VerifyBeforeChangeEmail (
83
+ result.data.email!! ,
84
+ result.data.previousEmail!!
85
+ )
86
+ " REVERT_SECOND_FACTOR_ADDITION" -> ActionCodeResult .RevertSecondFactorAddition (
87
+ result.data.email!! ,
88
+ result.data.multiFactorInfo?.let { MultiFactorInfo (it) }
89
+ )
90
+ else -> throw UnsupportedOperationException (result.operation)
91
+ } as T
92
+ }
78
93
}
79
94
80
95
actual class AuthResult internal constructor(val js : firebase.auth.AuthResult ) {
81
96
actual val user: FirebaseUser ?
82
97
get() = rethrow { js.user?.let { FirebaseUser (it) } }
83
98
}
84
99
85
- actual class ActionCodeResult (val js : firebase.auth.ActionCodeInfo ) {
86
- actual val operation: Operation
87
- get() = when (js.operation) {
88
- " PASSWORD_RESET" -> Operation .PasswordReset (this )
89
- " VERIFY_EMAIL" -> Operation .VerifyEmail (this )
90
- " RECOVER_EMAIL" -> Operation .RecoverEmail (this )
91
- " EMAIL_SIGNIN" -> Operation .SignInWithEmailLink
92
- " VERIFY_AND_CHANGE_EMAIL" -> Operation .VerifyBeforeChangeEmail (this )
93
- " REVERT_SECOND_FACTOR_ADDITION" -> Operation .RevertSecondFactorAddition (this )
94
- else -> Operation .Error
95
- }
96
- }
97
-
98
- internal actual sealed class ActionCodeDataType <out T > {
99
-
100
- actual abstract fun dataForResult (result : ActionCodeResult ): T
101
-
102
- actual object Email : ActionCodeDataType<String>() {
103
- override fun dataForResult (result : ActionCodeResult ): String = result.js.data.email!!
104
- }
105
- actual object PreviousEmail : ActionCodeDataType<String>() {
106
- override fun dataForResult (result : ActionCodeResult ): String = result.js.data.previousEmail!!
107
- }
108
- actual object MultiFactor : ActionCodeDataType<MultiFactorInfo?>() {
109
- override fun dataForResult (result : ActionCodeResult ): MultiFactorInfo ? = result.js.data.multiFactorInfo?.let { MultiFactorInfo (it) }
110
- }
111
- }
112
-
113
- actual class SignInMethodQueryResult (actual val signInMethods : List <String >)
114
-
115
100
private fun ActionCodeSettings.toJson () = json(
116
101
" android" to (androidPackageName?.run { json(" installApp" to installIfNotAvailable, " minimumVersion" to minimumVersion, " packageName" to packageName) } ? : undefined),
117
102
" dynamicLinkDomain" to (dynamicLinkDomain ? : undefined),
0 commit comments