Skip to content

Commit c57b201

Browse files
authored
Merge pull request #385 from GitLiveApp/updateProfileWorkaround
workaround for https://youtrack.jetbrains.com/issue/KT-48836
2 parents a3c295f + 4c0c7a5 commit c57b201

File tree

5 files changed

+20
-14
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
  • firebase-common/src/jsMain/kotlin/dev/gitlive/firebase

5 files changed

+20
-14
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ actual class FirebaseUser internal constructor(val android: com.google.firebase.
4848
actual suspend fun updatePhoneNumber(credential: PhoneAuthCredential) = android.updatePhoneNumber(credential.android).await().run { Unit }
4949
actual suspend fun updateProfile(displayName: String?, photoUrl: String?) {
5050
val request = UserProfileChangeRequest.Builder()
51-
.setDisplayName(displayName)
52-
.setPhotoUri(photoUrl?.let { Uri.parse(it) })
51+
.apply { if(displayName !== UNCHANGED) setDisplayName(displayName) }
52+
.apply { if(photoUrl !== UNCHANGED) setPhotoUri(photoUrl?.let { Uri.parse(it) }) }
5353
.build()
5454
android.updateProfile(request).await()
5555
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
package dev.gitlive.firebase.auth
66

7+
//workaround for https://youtrack.jetbrains.com/issue/KT-48836
8+
internal val UNCHANGED = ""
9+
710
expect class FirebaseUser {
811
val uid: String
912
val displayName: String?
@@ -28,7 +31,7 @@ expect class FirebaseUser {
2831
suspend fun updateEmail(email: String)
2932
suspend fun updatePassword(password: String)
3033
suspend fun updatePhoneNumber(credential: PhoneAuthCredential)
31-
suspend fun updateProfile(displayName: String? = this.displayName, photoUrl: String? = this.photoURL)
34+
suspend fun updateProfile(displayName: String? = UNCHANGED, photoUrl: String? = UNCHANGED)
3235
suspend fun verifyBeforeUpdateEmail(newEmail: String, actionCodeSettings: ActionCodeSettings? = null)
3336
}
3437

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
package dev.gitlive.firebase.auth
66

7-
import cocoapods.FirebaseAuth.*
7+
import cocoapods.FirebaseAuth.FIRAuthDataResult
8+
import cocoapods.FirebaseAuth.FIRUser
9+
import cocoapods.FirebaseAuth.FIRUserInfoProtocol
10+
import cocoapods.FirebaseAuth.FIRUserMetadata
811
import platform.Foundation.NSURL
912

1013
actual class FirebaseUser internal constructor(val ios: FIRUser) {
@@ -65,10 +68,9 @@ actual class FirebaseUser internal constructor(val ios: FIRUser) {
6568
actual suspend fun updatePassword(password: String) = ios.await { updatePassword(password, it) }.run { Unit }
6669
actual suspend fun updatePhoneNumber(credential: PhoneAuthCredential) = ios.await { updatePhoneNumberCredential(credential.ios, it) }.run { Unit }
6770
actual suspend fun updateProfile(displayName: String?, photoUrl: String?) {
68-
val request = ios.profileChangeRequest().apply {
69-
this.displayName = displayName
70-
this.photoURL = photoUrl?.let { NSURL.URLWithString(it) }
71-
}
71+
val request = ios.profileChangeRequest()
72+
.apply { if(displayName !== UNCHANGED) setDisplayName(displayName) }
73+
.apply { if(photoUrl !== UNCHANGED) setPhotoURL(photoUrl?.let { NSURL.URLWithString(it) }) }
7274
ios.await { request.commitChangesWithCompletion(it) }
7375
}
7476
actual suspend fun verifyBeforeUpdateEmail(newEmail: String, actionCodeSettings: ActionCodeSettings?) = ios.await {

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package dev.gitlive.firebase.auth
33
import dev.gitlive.firebase.firebase
44
import kotlinx.coroutines.await
55
import kotlin.js.Date
6+
import kotlin.js.json
67

78
actual class FirebaseUser internal constructor(val js: firebase.user.User) {
89
actual val uid: String
@@ -44,11 +45,11 @@ actual class FirebaseUser internal constructor(val js: firebase.user.User) {
4445
actual suspend fun updatePassword(password: String) = rethrow { js.updatePassword(password).await() }
4546
actual suspend fun updatePhoneNumber(credential: PhoneAuthCredential) = rethrow { js.updatePhoneNumber(credential.js).await() }
4647
actual suspend fun updateProfile(displayName: String?, photoUrl: String?) = rethrow {
47-
val request = object : firebase.user.ProfileUpdateRequest {
48-
override val displayName: String? = displayName
49-
override val photoURL: String? = photoUrl
50-
}
51-
js.updateProfile(request).await()
48+
val request = listOfNotNull(
49+
displayName.takeUnless { it === UNCHANGED }?.let { "displayName" to it },
50+
photoUrl.takeUnless { it === UNCHANGED }?.let { "photoURL" to it }
51+
)
52+
js.updateProfile(json(*request.toTypedArray())).await()
5253
}
5354
actual suspend fun verifyBeforeUpdateEmail(newEmail: String, actionCodeSettings: ActionCodeSettings?) = rethrow { js.verifyBeforeUpdateEmail(newEmail, actionCodeSettings?.toJson()).await() }
5455
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ external object firebase {
213213
fun updateEmail(newEmail: String): Promise<Unit>
214214
fun updatePassword(newPassword: String): Promise<Unit>
215215
fun updatePhoneNumber(phoneCredential: auth.AuthCredential): Promise<Unit>
216-
fun updateProfile(profile: ProfileUpdateRequest): Promise<Unit>
216+
fun updateProfile(profile: Json): Promise<Unit>
217217
fun verifyBeforeUpdateEmail(newEmail: String, actionCodeSettings: Any?): Promise<Unit>
218218
}
219219

0 commit comments

Comments
 (0)