Skip to content

Commit 377b887

Browse files
committed
Missing fields added to AuthResult
Adds missing fields to AuthResult and makes its constructor public
1 parent d0fd99e commit 377b887

File tree

6 files changed

+106
-4
lines changed
  • firebase-auth/src
    • androidMain/kotlin/dev/gitlive/firebase/auth
    • commonMain/kotlin/dev/gitlive/firebase/auth
    • iosMain/kotlin/dev/gitlive/firebase/auth
    • jsMain/kotlin/dev/gitlive/firebase/auth
    • jvmMain/kotlin/dev/gitlive/firebase/auth

6 files changed

+106
-4
lines changed

firebase-auth/src/androidMain/kotlin/dev/gitlive/firebase/auth/auth.kt

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,28 @@ actual class FirebaseAuth internal constructor(val android: com.google.firebase.
110110
actual fun useEmulator(host: String, port: Int) = android.useEmulator(host, port)
111111
}
112112

113-
actual class AuthResult internal constructor(val android: com.google.firebase.auth.AuthResult) {
113+
actual class AuthResult(
114+
val android: com.google.firebase.auth.AuthResult,
115+
) {
114116
actual val user: FirebaseUser?
115117
get() = android.user?.let { FirebaseUser(it) }
118+
actual val credential: AuthCredential?
119+
get() = android.credential?.let { AuthCredential(it) }
120+
actual val additionalUserInfo: AdditionalUserInfo?
121+
get() = android.additionalUserInfo?.let { AdditionalUserInfo(it) }
122+
}
123+
124+
actual class AdditionalUserInfo(
125+
val android: com.google.firebase.auth.AdditionalUserInfo,
126+
) {
127+
actual val providerId: String?
128+
get() = android.providerId
129+
actual val username: String?
130+
get() = android.username
131+
actual val profile: Map<String, Any?>?
132+
get() = android.profile
133+
actual val isNewUser: Boolean
134+
get() = android.isNewUser
116135
}
117136

118137
actual class AuthTokenResult(val android: com.google.firebase.auth.GetTokenResult) {

firebase-auth/src/commonMain/kotlin/dev/gitlive/firebase/auth/auth.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ expect class FirebaseAuth {
4141

4242
expect class AuthResult {
4343
val user: FirebaseUser?
44+
val credential: AuthCredential?
45+
val additionalUserInfo: AdditionalUserInfo?
46+
}
47+
48+
expect class AdditionalUserInfo {
49+
val providerId: String?
50+
val username: String?
51+
val profile: Map<String, Any?>?
52+
val isNewUser: Boolean
4453
}
4554

4655
expect class AuthTokenResult {

firebase-auth/src/iosMain/kotlin/dev/gitlive/firebase/auth/auth.kt

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ import kotlinx.coroutines.CompletableDeferred
1515
import kotlinx.coroutines.channels.awaitClose
1616
import kotlinx.coroutines.flow.callbackFlow
1717
import platform.Foundation.NSError
18+
import platform.Foundation.NSString
1819
import platform.Foundation.NSURL
20+
import kotlin.coroutines.suspendCoroutine
1921

2022

2123
actual val Firebase.auth
@@ -101,9 +103,36 @@ actual class FirebaseAuth internal constructor(val ios: FIRAuth) {
101103
actual fun useEmulator(host: String, port: Int) = ios.useEmulatorWithHost(host, port.toLong())
102104
}
103105

104-
actual class AuthResult internal constructor(val ios: FIRAuthDataResult) {
106+
actual class AuthResult(
107+
val ios: FIRAuthDataResult,
108+
) {
105109
actual val user: FirebaseUser?
106110
get() = FirebaseUser(ios.user)
111+
actual val credential: AuthCredential?
112+
get() = ios.credential?.let { AuthCredential(it) }
113+
actual val additionalUserInfo: AdditionalUserInfo?
114+
get() = ios.additionalUserInfo?.let { AdditionalUserInfo(it) }
115+
}
116+
117+
actual class AdditionalUserInfo(
118+
val ios: FIRAdditionalUserInfo,
119+
) {
120+
actual val providerId: String?
121+
get() = ios.providerID
122+
actual val username: String?
123+
get() = ios.username
124+
actual val profile: Map<String, Any?>?
125+
get() = ios.profile
126+
?.mapNotNull { (key, value) ->
127+
if (key is NSString && value != null) {
128+
key.toString() to value
129+
} else {
130+
null
131+
}
132+
}
133+
?.toMap()
134+
actual val isNewUser: Boolean
135+
get() = ios.newUser
107136
}
108137

109138
actual class AuthTokenResult(val ios: FIRAuthTokenResult) {

firebase-auth/src/jsMain/kotlin/dev/gitlive/firebase/auth/auth.kt

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import kotlinx.coroutines.channels.awaitClose
1414
import kotlinx.coroutines.flow.callbackFlow
1515
import kotlin.js.json
1616
import dev.gitlive.firebase.auth.externals.AuthResult as JsAuthResult
17+
import dev.gitlive.firebase.auth.externals.AdditionalUserInfo as JsAdditionalUserInfo
1718

1819
actual val Firebase.auth
1920
get() = rethrow { FirebaseAuth(getAuth()) }
@@ -106,9 +107,28 @@ actual class FirebaseAuth internal constructor(val js: Auth) {
106107
actual fun useEmulator(host: String, port: Int) = rethrow { connectAuthEmulator(js, "http://$host:$port") }
107108
}
108109

109-
actual class AuthResult internal constructor(val js: JsAuthResult) {
110+
actual class AuthResult(
111+
val js: JsAuthResult,
112+
) {
110113
actual val user: FirebaseUser?
111114
get() = rethrow { js.user?.let { FirebaseUser(it) } }
115+
actual val credential: AuthCredential?
116+
get() = rethrow { js.credential?.let { AuthCredential(it) } }
117+
actual val additionalUserInfo: AdditionalUserInfo?
118+
get() = js.additionalUserInfo?.let { AdditionalUserInfo(it) }
119+
}
120+
121+
actual class AdditionalUserInfo(
122+
val js: JsAdditionalUserInfo,
123+
) {
124+
actual val providerId: String?
125+
get() = js.providerId
126+
actual val username: String?
127+
get() = js.username
128+
actual val profile: Map<String, Any?>?
129+
get() = js.profile
130+
actual val isNewUser: Boolean
131+
get() = js.newUser
112132
}
113133

114134
actual class AuthTokenResult(val js: IdTokenResult) {

firebase-auth/src/jsMain/kotlin/dev/gitlive/firebase/auth/externals/auth.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,14 @@ external interface AuthResult {
170170
val credential: AuthCredential?
171171
val operationType: String?
172172
val user: User?
173+
val additionalUserInfo: AdditionalUserInfo?
174+
}
175+
176+
external interface AdditionalUserInfo {
177+
val providerId: String?
178+
val username: String?
179+
val profile: Map<String, Any?>?
180+
val newUser: Boolean
173181
}
174182

175183
external interface AuthCredential {

firebase-auth/src/jvmMain/kotlin/dev/gitlive/firebase/auth/auth.kt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,26 @@ actual class FirebaseAuth internal constructor(val android: com.google.firebase.
110110
actual fun useEmulator(host: String, port: Int) = android.useEmulator(host, port)
111111
}
112112

113-
actual class AuthResult internal constructor(val android: com.google.firebase.auth.AuthResult) {
113+
actual class AuthResult(
114+
val android: com.google.firebase.auth.AuthResult,
115+
) {
114116
actual val user: FirebaseUser?
115117
get() = android.user?.let { FirebaseUser(it) }
118+
actual val credential: AuthCredential?
119+
get() { throw NotImplementedError() }
120+
actual val additionalUserInfo: AdditionalUserInfo?
121+
get() { throw NotImplementedError() }
122+
}
123+
124+
actual class AdditionalUserInfo {
125+
actual val providerId: String?
126+
get() { throw NotImplementedError() }
127+
actual val username: String?
128+
get() { throw NotImplementedError() }
129+
actual val profile: Map<String, Any?>?
130+
get() { throw NotImplementedError() }
131+
actual val isNewUser: Boolean
132+
get() { throw NotImplementedError() }
116133
}
117134

118135
actual class AuthTokenResult(val android: com.google.firebase.auth.GetTokenResult) {

0 commit comments

Comments
 (0)