File tree Expand file tree Collapse file tree 5 files changed +20
-14
lines changed
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 Expand file tree Collapse file tree 5 files changed +20
-14
lines changed Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff line change 44
55package dev.gitlive.firebase.auth
66
7+ // workaround for https://youtrack.jetbrains.com/issue/KT-48836
8+ internal val UNCHANGED = " "
9+
710expect 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
Original file line number Diff line number Diff line change 44
55package 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
811import platform.Foundation.NSURL
912
1013actual 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 {
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package dev.gitlive.firebase.auth
33import dev.gitlive.firebase.firebase
44import kotlinx.coroutines.await
55import kotlin.js.Date
6+ import kotlin.js.json
67
78actual 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}
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments