Skip to content

Commit

Permalink
Removed the UNCHANGED logic from update profile
Browse files Browse the repository at this point in the history
Should work on K2
  • Loading branch information
Daeda88 committed Jun 11, 2024
1 parent e727265 commit 03e8702
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,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()
.apply { if(displayName !== UNCHANGED) setDisplayName(displayName) }
.apply { if(photoUrl !== UNCHANGED) photoUri = photoUrl?.let { Uri.parse(it) } }
.apply { setDisplayName(displayName) }
.apply { photoUri = photoUrl?.let { Uri.parse(it) } }
.build()
android.updateProfile(request).await()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

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?
Expand All @@ -32,7 +29,7 @@ expect class FirebaseUser {
suspend fun updateEmail(email: String)
suspend fun updatePassword(password: String)
suspend fun updatePhoneNumber(credential: PhoneAuthCredential)
suspend fun updateProfile(displayName: String? = UNCHANGED, photoUrl: String? = UNCHANGED)
suspend fun updateProfile(displayName: String? = this.displayName, photoUrl: String? = this.photoURL)
suspend fun verifyBeforeUpdateEmail(newEmail: String, actionCodeSettings: ActionCodeSettings? = null)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ actual class FirebaseUser internal constructor(val ios: FIRUser) {
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 { if(displayName !== UNCHANGED) setDisplayName(displayName) }
.apply { if(photoUrl !== UNCHANGED) setPhotoURL(photoUrl?.let { NSURL.URLWithString(it) }) }
.apply { setDisplayName(displayName) }
.apply { setPhotoURL(photoUrl?.let { NSURL.URLWithString(it) }) }
ios.await { request.commitChangesWithCompletion(it) }
}
actual suspend fun verifyBeforeUpdateEmail(newEmail: String, actionCodeSettings: ActionCodeSettings?) = ios.await {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ actual class FirebaseUser internal constructor(val js: User) {
actual suspend fun updatePassword(password: String) = rethrow { updatePassword(js, password).await() }
actual suspend fun updatePhoneNumber(credential: PhoneAuthCredential) = rethrow { updatePhoneNumber(js, credential.js).await() }
actual suspend fun updateProfile(displayName: String?, photoUrl: String?): Unit = rethrow {
val request = listOfNotNull(
displayName.takeUnless { it === UNCHANGED }?.let { "displayName" to it },
photoUrl.takeUnless { it === UNCHANGED }?.let { "photoURL" to it }
val request = listOf(
"displayName" to displayName,
"photoURL" to photoUrl,
)
updateProfile(js, json(*request.toTypedArray())).await()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
.apply { if(displayName !== UNCHANGED) setDisplayName(displayName) }
.apply { if(photoUrl !== UNCHANGED) setPhotoUri(photoUrl?.let { Uri.parse(it) }) }
.apply { setDisplayName(displayName) }
.apply { setPhotoUri(photoUrl?.let { Uri.parse(it) }) }
.build()
android.updateProfile(request).await()
}
Expand Down

0 comments on commit 03e8702

Please sign in to comment.