Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

workaround for https://youtrack.jetbrains.com/issue/KT-48836 #385

Merged
merged 1 commit into from
Jun 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
.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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ external object firebase {
fun updateEmail(newEmail: String): Promise<Unit>
fun updatePassword(newPassword: String): Promise<Unit>
fun updatePhoneNumber(phoneCredential: auth.AuthCredential): Promise<Unit>
fun updateProfile(profile: ProfileUpdateRequest): Promise<Unit>
fun updateProfile(profile: Json): Promise<Unit>
fun verifyBeforeUpdateEmail(newEmail: String, actionCodeSettings: Any?): Promise<Unit>
}

Expand Down