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.
48
48
actual suspend fun updatePhoneNumber (credential : PhoneAuthCredential ) = android.updatePhoneNumber(credential.android).await().run { Unit }
49
49
actual suspend fun updateProfile (displayName : String? , photoUrl : String? ) {
50
50
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) }) }
53
53
.build()
54
54
android.updateProfile(request).await()
55
55
}
Original file line number Diff line number Diff line change 4
4
5
5
package dev.gitlive.firebase.auth
6
6
7
+ // workaround for https://youtrack.jetbrains.com/issue/KT-48836
8
+ internal val UNCHANGED = " "
9
+
7
10
expect class FirebaseUser {
8
11
val uid: String
9
12
val displayName: String?
@@ -28,7 +31,7 @@ expect class FirebaseUser {
28
31
suspend fun updateEmail (email : String )
29
32
suspend fun updatePassword (password : String )
30
33
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 )
32
35
suspend fun verifyBeforeUpdateEmail (newEmail : String , actionCodeSettings : ActionCodeSettings ? = null)
33
36
}
34
37
Original file line number Diff line number Diff line change 4
4
5
5
package dev.gitlive.firebase.auth
6
6
7
- import cocoapods.FirebaseAuth.*
7
+ import cocoapods.FirebaseAuth.FIRAuthDataResult
8
+ import cocoapods.FirebaseAuth.FIRUser
9
+ import cocoapods.FirebaseAuth.FIRUserInfoProtocol
10
+ import cocoapods.FirebaseAuth.FIRUserMetadata
8
11
import platform.Foundation.NSURL
9
12
10
13
actual class FirebaseUser internal constructor(val ios : FIRUser ) {
@@ -65,10 +68,9 @@ actual class FirebaseUser internal constructor(val ios: FIRUser) {
65
68
actual suspend fun updatePassword (password : String ) = ios.await { updatePassword(password, it) }.run { Unit }
66
69
actual suspend fun updatePhoneNumber (credential : PhoneAuthCredential ) = ios.await { updatePhoneNumberCredential(credential.ios, it) }.run { Unit }
67
70
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) }) }
72
74
ios.await { request.commitChangesWithCompletion(it) }
73
75
}
74
76
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
3
3
import dev.gitlive.firebase.firebase
4
4
import kotlinx.coroutines.await
5
5
import kotlin.js.Date
6
+ import kotlin.js.json
6
7
7
8
actual class FirebaseUser internal constructor(val js : firebase.user.User ) {
8
9
actual val uid: String
@@ -44,11 +45,11 @@ actual class FirebaseUser internal constructor(val js: firebase.user.User) {
44
45
actual suspend fun updatePassword (password : String ) = rethrow { js.updatePassword(password).await() }
45
46
actual suspend fun updatePhoneNumber (credential : PhoneAuthCredential ) = rethrow { js.updatePhoneNumber(credential.js).await() }
46
47
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()
52
53
}
53
54
actual suspend fun verifyBeforeUpdateEmail (newEmail : String , actionCodeSettings : ActionCodeSettings ? ) = rethrow { js.verifyBeforeUpdateEmail(newEmail, actionCodeSettings?.toJson()).await() }
54
55
}
Original file line number Diff line number Diff line change @@ -213,7 +213,7 @@ external object firebase {
213
213
fun updateEmail (newEmail : String ): Promise <Unit >
214
214
fun updatePassword (newPassword : String ): Promise <Unit >
215
215
fun updatePhoneNumber (phoneCredential : auth.AuthCredential ): Promise <Unit >
216
- fun updateProfile (profile : ProfileUpdateRequest ): Promise <Unit >
216
+ fun updateProfile (profile : Json ): Promise <Unit >
217
217
fun verifyBeforeUpdateEmail (newEmail : String , actionCodeSettings : Any? ): Promise <Unit >
218
218
}
219
219
You can’t perform that action at this time.
0 commit comments