55package dev.gitlive.firebase.auth
66
77import dev.gitlive.firebase.*
8+ import dev.gitlive.firebase.FirebaseApp
9+ import dev.gitlive.firebase.auth.externals.*
810import kotlinx.coroutines.await
911import kotlinx.coroutines.channels.awaitClose
1012import kotlinx.coroutines.flow.callbackFlow
1113import kotlin.js.json
14+ import dev.gitlive.firebase.auth.externals.AuthResult as JsAuthResult
1215
1316actual val Firebase .auth
14- get() = rethrow { dev.gitlive.firebase.auth; FirebaseAuth (firebase.auth ()) }
17+ get() = rethrow { FirebaseAuth (getAuth ()) }
1518
1619actual fun Firebase.auth (app : FirebaseApp ) =
17- rethrow { dev.gitlive.firebase.auth; FirebaseAuth (firebase.auth (app.js)) }
20+ rethrow { FirebaseAuth (getAuth (app.js)) }
1821
19- actual class FirebaseAuth internal constructor(val js : firebase.auth. Auth ) {
22+ actual class FirebaseAuth internal constructor(val js : Auth ) {
2023
2124 actual val currentUser: FirebaseUser ?
2225 get() = rethrow { js.currentUser?.let { FirebaseUser (it) } }
@@ -39,47 +42,47 @@ actual class FirebaseAuth internal constructor(val js: firebase.auth.Auth) {
3942 get() = js.languageCode ? : " "
4043 set(value) { js.languageCode = value }
4144
42- actual suspend fun applyActionCode (code : String ) = rethrow { js. applyActionCode(code).await() }
43- actual suspend fun confirmPasswordReset (code : String , newPassword : String ) = rethrow { js. confirmPasswordReset(code, newPassword).await() }
45+ actual suspend fun applyActionCode (code : String ) = rethrow { applyActionCode(js, code).await() }
46+ actual suspend fun confirmPasswordReset (code : String , newPassword : String ) = rethrow { confirmPasswordReset(js, code, newPassword).await() }
4447
4548 actual suspend fun createUserWithEmailAndPassword (email : String , password : String ) =
46- rethrow { AuthResult (js. createUserWithEmailAndPassword(email, password).await()) }
49+ rethrow { AuthResult (createUserWithEmailAndPassword(js, email, password).await()) }
4750
48- actual suspend fun fetchSignInMethodsForEmail (email : String ): List <String > = rethrow { js. fetchSignInMethodsForEmail(email).await().asList() }
51+ actual suspend fun fetchSignInMethodsForEmail (email : String ): List <String > = rethrow { fetchSignInMethodsForEmail(js, email).await().asList() }
4952
5053 actual suspend fun sendPasswordResetEmail (email : String , actionCodeSettings : ActionCodeSettings ? ) =
51- rethrow { js. sendPasswordResetEmail(email, actionCodeSettings?.toJson()).await() }
54+ rethrow { sendPasswordResetEmail(js, email, actionCodeSettings?.toJson()).await() }
5255
5356 actual suspend fun sendSignInLinkToEmail (email : String , actionCodeSettings : ActionCodeSettings ) =
54- rethrow { js. sendSignInLinkToEmail(email, actionCodeSettings.toJson()).await() }
57+ rethrow { sendSignInLinkToEmail(js, email, actionCodeSettings.toJson()).await() }
5558
56- actual fun isSignInWithEmailLink (link : String ) = rethrow { js. isSignInWithEmailLink(link) }
59+ actual fun isSignInWithEmailLink (link : String ) = rethrow { isSignInWithEmailLink(js, link) }
5760
5861 actual suspend fun signInWithEmailAndPassword (email : String , password : String ) =
59- rethrow { AuthResult (js. signInWithEmailAndPassword(email, password).await()) }
62+ rethrow { AuthResult (signInWithEmailAndPassword(js, email, password).await()) }
6063
6164 actual suspend fun signInWithCustomToken (token : String ) =
62- rethrow { AuthResult (js. signInWithCustomToken(token).await()) }
65+ rethrow { AuthResult (signInWithCustomToken(js, token).await()) }
6366
6467 actual suspend fun signInAnonymously () =
65- rethrow { AuthResult (js. signInAnonymously().await()) }
68+ rethrow { AuthResult (signInAnonymously(js ).await()) }
6669
6770 actual suspend fun signInWithCredential (authCredential : AuthCredential ) =
68- rethrow { AuthResult (js. signInWithCredential(authCredential.js).await()) }
71+ rethrow { AuthResult (signInWithCredential(js, authCredential.js).await()) }
6972
7073 actual suspend fun signInWithEmailLink (email : String , link : String ) =
71- rethrow { AuthResult (js. signInWithEmailLink(email, link).await()) }
74+ rethrow { AuthResult (signInWithEmailLink(js, email, link).await()) }
7275
73- actual suspend fun signOut () = rethrow { js. signOut().await() }
76+ actual suspend fun signOut () = rethrow { signOut(js ).await() }
7477
7578 actual suspend fun updateCurrentUser (user : FirebaseUser ) =
76- rethrow { js. updateCurrentUser(user.js).await() }
79+ rethrow { updateCurrentUser(js, user.js).await() }
7780
7881 actual suspend fun verifyPasswordResetCode (code : String ): String =
79- rethrow { js. verifyPasswordResetCode(code).await() }
82+ rethrow { verifyPasswordResetCode(js, code).await() }
8083
8184 actual suspend fun <T : ActionCodeResult > checkActionCode (code : String ): T = rethrow {
82- val result = js. checkActionCode(code).await()
85+ val result = checkActionCode(js, code).await()
8386 @Suppress(" UNCHECKED_CAST" )
8487 return when (result.operation) {
8588 " EMAIL_SIGNIN" -> ActionCodeResult .SignInWithEmailLink
@@ -98,15 +101,15 @@ actual class FirebaseAuth internal constructor(val js: firebase.auth.Auth) {
98101 } as T
99102 }
100103
101- actual fun useEmulator (host : String , port : Int ) = rethrow { js.useEmulator( " http://$host :$port " ) }
104+ actual fun useEmulator (host : String , port : Int ) = rethrow { connectAuthEmulator(js, " http://$host :$port " ) }
102105}
103106
104- actual class AuthResult internal constructor(val js : firebase.auth. AuthResult ) {
107+ actual class AuthResult internal constructor(val js : JsAuthResult ) {
105108 actual val user: FirebaseUser ?
106109 get() = rethrow { js.user?.let { FirebaseUser (it) } }
107110}
108111
109- actual class AuthTokenResult (val js : firebase.auth. IdTokenResult ) {
112+ actual class AuthTokenResult (val js : IdTokenResult ) {
110113// actual val authTimestamp: Long
111114// get() = js.authTime
112115 actual val claims: Map <String , Any >
0 commit comments