diff --git a/firebase-auth/src/androidMain/kotlin/dev/gitlive/firebase/auth/user.kt b/firebase-auth/src/androidMain/kotlin/dev/gitlive/firebase/auth/user.kt index 47a942bdb..ba7c7bb64 100644 --- a/firebase-auth/src/androidMain/kotlin/dev/gitlive/firebase/auth/user.kt +++ b/firebase-auth/src/androidMain/kotlin/dev/gitlive/firebase/auth/user.kt @@ -48,8 +48,8 @@ actual class FirebaseUser internal constructor(val android: com.google.firebase. actual suspend fun updatePhoneNumber(credential: PhoneAuthCredential) = android.updatePhoneNumber(credential.android).await().run { Unit } actual suspend fun updateProfile(displayName: String?, photoUrl: String?) { val request = UserProfileChangeRequest.Builder() - .setDisplayName(displayName) - .setPhotoUri(photoUrl?.let { Uri.parse(it) }) + .apply { if(displayName !== UNCHANGED) setDisplayName(displayName) } + .apply { if(photoUrl !== UNCHANGED) setPhotoUri(photoUrl?.let { Uri.parse(it) }) } .build() android.updateProfile(request).await() } diff --git a/firebase-auth/src/commonMain/kotlin/dev/gitlive/firebase/auth/user.kt b/firebase-auth/src/commonMain/kotlin/dev/gitlive/firebase/auth/user.kt index 3d00c412f..92e9083b0 100644 --- a/firebase-auth/src/commonMain/kotlin/dev/gitlive/firebase/auth/user.kt +++ b/firebase-auth/src/commonMain/kotlin/dev/gitlive/firebase/auth/user.kt @@ -4,6 +4,9 @@ package dev.gitlive.firebase.auth +//workaround for https://youtrack.jetbrains.com/issue/KT-48836 +internal val UNCHANGED = "" + expect class FirebaseUser { val uid: String val displayName: String? @@ -28,7 +31,7 @@ expect class FirebaseUser { suspend fun updateEmail(email: String) suspend fun updatePassword(password: String) suspend fun updatePhoneNumber(credential: PhoneAuthCredential) - suspend fun updateProfile(displayName: String? = this.displayName, photoUrl: String? = this.photoURL) + suspend fun updateProfile(displayName: String? = UNCHANGED, photoUrl: String? = UNCHANGED) suspend fun verifyBeforeUpdateEmail(newEmail: String, actionCodeSettings: ActionCodeSettings? = null) } diff --git a/firebase-auth/src/iosMain/kotlin/dev/gitlive/firebase/auth/user.kt b/firebase-auth/src/iosMain/kotlin/dev/gitlive/firebase/auth/user.kt index d322fdb4c..a765e10eb 100644 --- a/firebase-auth/src/iosMain/kotlin/dev/gitlive/firebase/auth/user.kt +++ b/firebase-auth/src/iosMain/kotlin/dev/gitlive/firebase/auth/user.kt @@ -4,7 +4,10 @@ package dev.gitlive.firebase.auth -import cocoapods.FirebaseAuth.* +import cocoapods.FirebaseAuth.FIRAuthDataResult +import cocoapods.FirebaseAuth.FIRUser +import cocoapods.FirebaseAuth.FIRUserInfoProtocol +import cocoapods.FirebaseAuth.FIRUserMetadata import platform.Foundation.NSURL actual class FirebaseUser internal constructor(val ios: FIRUser) { @@ -65,10 +68,9 @@ actual class FirebaseUser internal constructor(val ios: FIRUser) { actual suspend fun updatePassword(password: String) = ios.await { updatePassword(password, it) }.run { Unit } actual suspend fun updatePhoneNumber(credential: PhoneAuthCredential) = ios.await { updatePhoneNumberCredential(credential.ios, it) }.run { Unit } actual suspend fun updateProfile(displayName: String?, photoUrl: String?) { - val request = ios.profileChangeRequest().apply { - this.displayName = displayName - this.photoURL = photoUrl?.let { NSURL.URLWithString(it) } - } + val request = ios.profileChangeRequest() + .apply { if(displayName !== UNCHANGED) setDisplayName(displayName) } + .apply { if(photoUrl !== UNCHANGED) setPhotoURL(photoUrl?.let { NSURL.URLWithString(it) }) } ios.await { request.commitChangesWithCompletion(it) } } actual suspend fun verifyBeforeUpdateEmail(newEmail: String, actionCodeSettings: ActionCodeSettings?) = ios.await { diff --git a/firebase-auth/src/jsMain/kotlin/dev/gitlive/firebase/auth/user.kt b/firebase-auth/src/jsMain/kotlin/dev/gitlive/firebase/auth/user.kt index ab6cb796e..ec0070a9e 100644 --- a/firebase-auth/src/jsMain/kotlin/dev/gitlive/firebase/auth/user.kt +++ b/firebase-auth/src/jsMain/kotlin/dev/gitlive/firebase/auth/user.kt @@ -3,6 +3,7 @@ package dev.gitlive.firebase.auth import dev.gitlive.firebase.firebase import kotlinx.coroutines.await import kotlin.js.Date +import kotlin.js.json actual class FirebaseUser internal constructor(val js: firebase.user.User) { actual val uid: String @@ -44,11 +45,11 @@ actual class FirebaseUser internal constructor(val js: firebase.user.User) { actual suspend fun updatePassword(password: String) = rethrow { js.updatePassword(password).await() } actual suspend fun updatePhoneNumber(credential: PhoneAuthCredential) = rethrow { js.updatePhoneNumber(credential.js).await() } actual suspend fun updateProfile(displayName: String?, photoUrl: String?) = rethrow { - val request = object : firebase.user.ProfileUpdateRequest { - override val displayName: String? = displayName - override val photoURL: String? = photoUrl - } - js.updateProfile(request).await() + val request = listOfNotNull( + displayName.takeUnless { it === UNCHANGED }?.let { "displayName" to it }, + photoUrl.takeUnless { it === UNCHANGED }?.let { "photoURL" to it } + ) + js.updateProfile(json(*request.toTypedArray())).await() } actual suspend fun verifyBeforeUpdateEmail(newEmail: String, actionCodeSettings: ActionCodeSettings?) = rethrow { js.verifyBeforeUpdateEmail(newEmail, actionCodeSettings?.toJson()).await() } } diff --git a/firebase-common/src/jsMain/kotlin/dev/gitlive/firebase/externals.kt b/firebase-common/src/jsMain/kotlin/dev/gitlive/firebase/externals.kt index 544575171..1ff8f04e1 100644 --- a/firebase-common/src/jsMain/kotlin/dev/gitlive/firebase/externals.kt +++ b/firebase-common/src/jsMain/kotlin/dev/gitlive/firebase/externals.kt @@ -213,7 +213,7 @@ external object firebase { fun updateEmail(newEmail: String): Promise fun updatePassword(newPassword: String): Promise fun updatePhoneNumber(phoneCredential: auth.AuthCredential): Promise - fun updateProfile(profile: ProfileUpdateRequest): Promise + fun updateProfile(profile: Json): Promise fun verifyBeforeUpdateEmail(newEmail: String, actionCodeSettings: Any?): Promise }