5
5
package dev.gitlive.firebase.auth
6
6
7
7
import dev.gitlive.firebase.*
8
+ import dev.gitlive.firebase.FirebaseApp
9
+ import dev.gitlive.firebase.externals.*
8
10
import kotlinx.coroutines.await
9
11
import kotlinx.coroutines.channels.awaitClose
10
12
import kotlinx.coroutines.flow.callbackFlow
11
13
import kotlin.js.json
14
+ import dev.gitlive.firebase.externals.AuthResult as JsAuthResult
12
15
13
16
actual val Firebase .auth
14
- get() = rethrow { dev.gitlive.firebase.auth; FirebaseAuth (firebase.auth ()) }
17
+ get() = rethrow { FirebaseAuth (getAuth ()) }
15
18
16
19
actual fun Firebase.auth (app : FirebaseApp ) =
17
- rethrow { dev.gitlive.firebase.auth; FirebaseAuth (firebase.auth (app.js)) }
20
+ rethrow { FirebaseAuth (getAuth (app.js)) }
18
21
19
- actual class FirebaseAuth internal constructor(val js : firebase.auth. Auth ) {
22
+ actual class FirebaseAuth internal constructor(val js : Auth ) {
20
23
21
24
actual val currentUser: FirebaseUser ?
22
25
get() = rethrow { js.currentUser?.let { FirebaseUser (it) } }
@@ -39,47 +42,51 @@ actual class FirebaseAuth internal constructor(val js: firebase.auth.Auth) {
39
42
get() = js.languageCode ? : " "
40
43
set(value) { js.languageCode = value }
41
44
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 {
47
+ confirmPasswordReset(js, code, newPassword).await()
48
+ }
44
49
45
50
actual suspend fun createUserWithEmailAndPassword (email : String , password : String ) =
46
- rethrow { AuthResult (js. createUserWithEmailAndPassword(email, password).await()) }
51
+ rethrow { AuthResult (createUserWithEmailAndPassword(js, email, password).await()) }
47
52
48
- actual suspend fun fetchSignInMethodsForEmail (email : String ): List <String > = rethrow { js.fetchSignInMethodsForEmail(email).await().asList() }
53
+ actual suspend fun fetchSignInMethodsForEmail (email : String ): List <String > = rethrow {
54
+ fetchSignInMethodsForEmail(js, email).await().asList()
55
+ }
49
56
50
57
actual suspend fun sendPasswordResetEmail (email : String , actionCodeSettings : ActionCodeSettings ? ) =
51
- rethrow { js. sendPasswordResetEmail(email, actionCodeSettings?.toJson()).await() }
58
+ rethrow { sendPasswordResetEmail(js, email, actionCodeSettings?.toJson()).await() }
52
59
53
60
actual suspend fun sendSignInLinkToEmail (email : String , actionCodeSettings : ActionCodeSettings ) =
54
- rethrow { js. sendSignInLinkToEmail(email, actionCodeSettings.toJson()).await() }
61
+ rethrow { sendSignInLinkToEmail(js, email, actionCodeSettings.toJson()).await() }
55
62
56
- actual fun isSignInWithEmailLink (link : String ) = rethrow { js. isSignInWithEmailLink(link) }
63
+ actual fun isSignInWithEmailLink (link : String ) = rethrow { isSignInWithEmailLink(js, link) }
57
64
58
65
actual suspend fun signInWithEmailAndPassword (email : String , password : String ) =
59
- rethrow { AuthResult (js. signInWithEmailAndPassword(email, password).await()) }
66
+ rethrow { AuthResult (signInWithEmailAndPassword(js, email, password).await()) }
60
67
61
68
actual suspend fun signInWithCustomToken (token : String ) =
62
- rethrow { AuthResult (js. signInWithCustomToken(token).await()) }
69
+ rethrow { AuthResult (signInWithCustomToken(js, token).await()) }
63
70
64
71
actual suspend fun signInAnonymously () =
65
- rethrow { AuthResult (js. signInAnonymously().await()) }
72
+ rethrow { AuthResult (signInAnonymously(js ).await()) }
66
73
67
74
actual suspend fun signInWithCredential (authCredential : AuthCredential ) =
68
- rethrow { AuthResult (js. signInWithCredential(authCredential.js).await()) }
75
+ rethrow { AuthResult (signInWithCredential(js, authCredential.js).await()) }
69
76
70
77
actual suspend fun signInWithEmailLink (email : String , link : String ) =
71
- rethrow { AuthResult (js. signInWithEmailLink(email, link).await()) }
78
+ rethrow { AuthResult (signInWithEmailLink(js, email, link).await()) }
72
79
73
- actual suspend fun signOut () = rethrow { js. signOut().await() }
80
+ actual suspend fun signOut () = rethrow { signOut(js ).await() }
74
81
75
82
actual suspend fun updateCurrentUser (user : FirebaseUser ) =
76
- rethrow { js. updateCurrentUser(user.js).await() }
83
+ rethrow { updateCurrentUser(js, user.js).await() }
77
84
78
85
actual suspend fun verifyPasswordResetCode (code : String ): String =
79
- rethrow { js. verifyPasswordResetCode(code).await() }
86
+ rethrow { verifyPasswordResetCode(js, code).await() }
80
87
81
88
actual suspend fun <T : ActionCodeResult > checkActionCode (code : String ): T = rethrow {
82
- val result = js. checkActionCode(code).await()
89
+ val result = checkActionCode(js, code).await()
83
90
@Suppress(" UNCHECKED_CAST" )
84
91
return when (result.operation) {
85
92
" EMAIL_SIGNIN" -> ActionCodeResult .SignInWithEmailLink
@@ -98,15 +105,17 @@ actual class FirebaseAuth internal constructor(val js: firebase.auth.Auth) {
98
105
} as T
99
106
}
100
107
101
- actual fun useEmulator (host : String , port : Int ) = rethrow { js.useEmulator(" http://$host :$port " ) }
108
+ actual fun useEmulator (host : String , port : Int ) = rethrow {
109
+ connectAuthEmulator(js, " http://$host :$port " )
110
+ }
102
111
}
103
112
104
- actual class AuthResult internal constructor(val js : firebase.auth. AuthResult ) {
113
+ actual class AuthResult internal constructor(val js : JsAuthResult ) {
105
114
actual val user: FirebaseUser ?
106
115
get() = rethrow { js.user?.let { FirebaseUser (it) } }
107
116
}
108
117
109
- actual class AuthTokenResult (val js : firebase.auth. IdTokenResult ) {
118
+ actual class AuthTokenResult (val js : IdTokenResult ) {
110
119
// actual val authTimestamp: Long
111
120
// get() = js.authTime
112
121
actual val claims: Map <String , Any >
0 commit comments