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

Missing fields added to AuthResult #556

Merged
merged 27 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
377b887
Missing fields added to AuthResult
mr-kew Jun 27, 2024
a737063
Merge branch 'master' into auth-result
mr-kew Jun 27, 2024
4885a5d
Merge branch 'master' into auth-result
nbransby Jun 27, 2024
dcd28c7
Merge branch 'master' into auth-result
nbransby Jun 30, 2024
31d8466
Removed unused import
mr-kew Jun 30, 2024
37867cf
AuthResult test
mr-kew Jun 30, 2024
3a7f273
Merge branch 'master' into auth-result
nbransby Jul 12, 2024
93b9dda
Added messages to asserts in AuthResult test
mr-kew Jul 15, 2024
ef5e5d9
JVM lint issues fixed
mr-kew Jul 15, 2024
be998c3
JVM lint issues properly fixed
mr-kew Jul 15, 2024
f2c2c51
Public api updated
mr-kew Jul 15, 2024
ed24041
Public api fix
mr-kew Jul 15, 2024
434abaa
AuthResult structure test allows null values
mr-kew Jul 15, 2024
84cdf2c
AuthResult structure test unwrap fixed
mr-kew Jul 15, 2024
a18e3f2
AuthResult structure additionalUserInfo exists
mr-kew Jul 15, 2024
79a7516
AuthResult structure isNewUser default respected
mr-kew Jul 15, 2024
ac4cffa
AuthResult structure test made more forgiving
Jul 17, 2024
277e7f5
Merge branch 'master' into auth-result
mr-kew Aug 16, 2024
e5af67d
AuthResult map parsing fixed in JS
mr-kew Aug 28, 2024
9681cf4
Used Json? instead od dynamic for better clarity
mr-kew Aug 28, 2024
fad3664
AuthResult structure JS test fixed
mr-kew Aug 28, 2024
60e42c0
Merge branch 'master' into auth-result
mr-kew Aug 29, 2024
b566e31
Merge cleanup
mr-kew Aug 29, 2024
1a9a14a
API dump
mr-kew Aug 29, 2024
3eb1a0c
Native properties moved into extensions
mr-kew Aug 29, 2024
ecfa47d
Merge branch 'master' into auth-result
nbransby Aug 30, 2024
9e8ef04
Update auth.kt
nbransby Aug 30, 2024
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
12 changes: 12 additions & 0 deletions firebase-auth/api/android/firebase-auth.api
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ public final class dev/gitlive/firebase/auth/ActionCodeSettings {
public fun toString ()Ljava/lang/String;
}

public final class dev/gitlive/firebase/auth/AdditionalUserInfo {
public fun <init> (Lcom/google/firebase/auth/AdditionalUserInfo;)V
public final fun getProfile ()Ljava/util/Map;
public final fun getProviderId ()Ljava/lang/String;
public final fun getUsername ()Ljava/lang/String;
public final fun isNewUser ()Z
}

public final class dev/gitlive/firebase/auth/AndroidPackageName {
public fun <init> (Ljava/lang/String;ZLjava/lang/String;)V
public synthetic fun <init> (Ljava/lang/String;ZLjava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
Expand All @@ -74,6 +82,9 @@ public class dev/gitlive/firebase/auth/AuthCredential {
}

public final class dev/gitlive/firebase/auth/AuthResult {
public fun <init> (Lcom/google/firebase/auth/AuthResult;)V
public final fun getAdditionalUserInfo ()Ldev/gitlive/firebase/auth/AdditionalUserInfo;
public final fun getCredential ()Ldev/gitlive/firebase/auth/AuthCredential;
public final fun getUser ()Ldev/gitlive/firebase/auth/FirebaseUser;
}

Expand Down Expand Up @@ -278,6 +289,7 @@ public final class dev/gitlive/firebase/auth/UserMetaData {

public final class dev/gitlive/firebase/auth/android {
public static final fun auth (Ldev/gitlive/firebase/Firebase;Ldev/gitlive/firebase/FirebaseApp;)Ldev/gitlive/firebase/auth/FirebaseAuth;
public static final fun getAndroid (Ldev/gitlive/firebase/auth/AdditionalUserInfo;)Lcom/google/firebase/auth/AdditionalUserInfo;
public static final fun getAndroid (Ldev/gitlive/firebase/auth/AuthResult;)Lcom/google/firebase/auth/AuthResult;
public static final fun getAndroid (Ldev/gitlive/firebase/auth/AuthTokenResult;)Lcom/google/firebase/auth/GetTokenResult;
public static final fun getAndroid (Ldev/gitlive/firebase/auth/FirebaseAuth;)Lcom/google/firebase/auth/FirebaseAuth;
Expand Down
11 changes: 11 additions & 0 deletions firebase-auth/api/jvm/firebase-auth.api
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ public final class dev/gitlive/firebase/auth/ActionCodeSettings {
public fun toString ()Ljava/lang/String;
}

public final class dev/gitlive/firebase/auth/AdditionalUserInfo {
public fun <init> ()V
public final fun getProfile ()Ljava/util/Map;
public final fun getProviderId ()Ljava/lang/String;
public final fun getUsername ()Ljava/lang/String;
public final fun isNewUser ()Z
}

public final class dev/gitlive/firebase/auth/AndroidPackageName {
public fun <init> (Ljava/lang/String;ZLjava/lang/String;)V
public synthetic fun <init> (Ljava/lang/String;ZLjava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
Expand All @@ -74,6 +82,9 @@ public class dev/gitlive/firebase/auth/AuthCredential {
}

public final class dev/gitlive/firebase/auth/AuthResult {
public fun <init> (Lcom/google/firebase/auth/AuthResult;)V
public final fun getAdditionalUserInfo ()Ldev/gitlive/firebase/auth/AdditionalUserInfo;
public final fun getCredential ()Ldev/gitlive/firebase/auth/AuthCredential;
public final fun getUser ()Ldev/gitlive/firebase/auth/FirebaseUser;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,29 @@ public actual class FirebaseAuth internal constructor(internal val android: com.

public val AuthResult.android: com.google.firebase.auth.AuthResult get() = android

public actual class AuthResult internal constructor(internal val android: com.google.firebase.auth.AuthResult) {
public actual class AuthResult(internal val android: com.google.firebase.auth.AuthResult) {
public actual val user: FirebaseUser?
get() = android.user?.let { FirebaseUser(it) }
public actual val credential: AuthCredential?
get() = android.credential?.let { AuthCredential(it) }
public actual val additionalUserInfo: AdditionalUserInfo?
get() = android.additionalUserInfo?.let { AdditionalUserInfo(it) }
}

public val AdditionalUserInfo.android: com.google.firebase.auth.AdditionalUserInfo
get() = android

public actual class AdditionalUserInfo(
internal val android: com.google.firebase.auth.AdditionalUserInfo,
) {
public actual val providerId: String?
get() = android.providerId
public actual val username: String?
get() = android.username
public actual val profile: Map<String, Any?>?
get() = android.profile
public actual val isNewUser: Boolean
get() = android.isNewUser
}

public val AuthTokenResult.android: com.google.firebase.auth.GetTokenResult get() = android
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ public expect class FirebaseAuth {

public expect class AuthResult {
public val user: FirebaseUser?
public val credential: AuthCredential?
public val additionalUserInfo: AdditionalUserInfo?
}

public expect class AdditionalUserInfo {
public val providerId: String?
public val username: String?
public val profile: Map<String, Any?>?
public val isNewUser: Boolean
}

public expect class AuthTokenResult {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,22 @@ class FirebaseAuthTest {
assertEquals(uid, result.user!!.uid)
}

@Test
fun testAuthResultStructure() = runTest {
val uid = getTestUid("[email protected]", "test123")
val result = auth.signInWithEmailAndPassword("[email protected]", "test123")
assertNotNull(result.user, "User does not exist.")
assertEquals(uid, result.user!!.uid, "uid does not match.")
assertNull(result.credential, "Credential throws.")
// Just test if it does not throw
result.additionalUserInfo?.let { additionalUserInfo ->
additionalUserInfo.providerId
additionalUserInfo.username
additionalUserInfo.profile
additionalUserInfo.isNewUser
}
}

@Test
fun testIsSignInWithEmailLink() {
val validLink = "http://localhost:9099/emulator/action?mode=signIn&lang=en&oobCode=_vr0QcFcxcVeLZbrcU-GpTaZiuxlHquqdC8MSy0YM_vzWCTAQgV9Jq&apiKey=fake-api-key&continueUrl=https%3A%2F%2Fexample.com%2Fsignin"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.Flow
import platform.Foundation.NSError
import platform.Foundation.NSString
import platform.Foundation.NSURL

public val FirebaseAuth.ios: FIRAuth get() = FIRAuth.auth()
Expand Down Expand Up @@ -104,11 +105,39 @@ public actual class FirebaseAuth internal constructor(internal val ios: FIRAuth)

public actual fun useEmulator(host: String, port: Int): Unit = ios.useEmulatorWithHost(host, port.toLong())
}

public val AuthResult.ios: FIRAuthDataResult get() = ios

public actual class AuthResult internal constructor(internal val ios: FIRAuthDataResult) {
public actual class AuthResult(internal val ios: FIRAuthDataResult) {
public actual val user: FirebaseUser?
get() = FirebaseUser(ios.user())
public actual val credential: AuthCredential?
get() = ios.credential()?.let { AuthCredential(it) }
public actual val additionalUserInfo: AdditionalUserInfo?
get() = ios.additionalUserInfo()?.let { AdditionalUserInfo(it) }
}

public val AdditionalUserInfo.ios: FIRAdditionalUserInfo get() = ios

public actual class AdditionalUserInfo(
internal val ios: FIRAdditionalUserInfo,
) {
public actual val providerId: String?
get() = ios.providerID()
public actual val username: String?
get() = ios.username()
public actual val profile: Map<String, Any?>?
get() = ios.profile()
?.mapNotNull { (key, value) ->
if (key is NSString && value != null) {
key.toString() to value
} else {
null
}
}
?.toMap()
public actual val isNewUser: Boolean
get() = ios.newUser()
}

public val AuthTokenResult.ios: FIRAuthTokenResult get() = ios
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ import kotlinx.coroutines.await
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.callbackFlow
import kotlin.js.Json
import kotlin.js.json
import dev.gitlive.firebase.auth.externals.AuthResult as JsAuthResult
import dev.gitlive.firebase.auth.externals.AdditionalUserInfo as JsAdditionalUserInfo

public actual val Firebase.auth: FirebaseAuth
get() = rethrow { FirebaseAuth(getAuth()) }
Expand Down Expand Up @@ -133,9 +135,34 @@ public actual class FirebaseAuth internal constructor(internal val js: Auth) {

public val AuthResult.js: JsAuthResult get() = js

public actual class AuthResult internal constructor(internal val js: JsAuthResult) {
public actual class AuthResult(internal val js: JsAuthResult) {
public actual val user: FirebaseUser?
get() = rethrow { js.user?.let { FirebaseUser(it) } }
public actual val credential: AuthCredential?
get() = rethrow { js.credential?.let { AuthCredential(it) } }
public actual val additionalUserInfo: AdditionalUserInfo?
get() = rethrow { js.additionalUserInfo?.let { AdditionalUserInfo(it) } }
}

public val AdditionalUserInfo.js: JsAdditionalUserInfo get() = js

public actual class AdditionalUserInfo(
internal val js: JsAdditionalUserInfo,
) {
public actual val providerId: String?
get() = js.providerId
public actual val username: String?
get() = js.username
public actual val profile: Map<String, Any?>?
get() = rethrow {
val profile = js.profile ?: return@rethrow null
val entries = js("Object.entries") as (Json) -> Array<Array<Any?>>
return@rethrow entries
.invoke(profile)
.associate { entry -> entry[0] as String to entry[1] }
}
public actual val isNewUser: Boolean
get() = js.newUser
}

public val AuthTokenResult.js: IdTokenResult get() = js
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,14 @@ public external interface AuthResult {
public val credential: AuthCredential?
public val operationType: String?
public val user: User?
public val additionalUserInfo: AdditionalUserInfo?
}

public external interface AdditionalUserInfo {
public val providerId: String?
public val username: String?
public val profile: Json?
public val newUser: Boolean
}

public external interface AuthCredential {
Expand Down
19 changes: 17 additions & 2 deletions firebase-auth/src/jvmMain/kotlin/dev/gitlive/firebase/auth/auth.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.tasks.await

public actual val Firebase.auth
public actual val Firebase.auth: FirebaseAuth
get() = FirebaseAuth(com.google.firebase.auth.FirebaseAuth.getInstance())

public actual fun Firebase.auth(app: FirebaseApp) =
Expand Down Expand Up @@ -127,9 +127,24 @@ public actual class FirebaseAuth internal constructor(internal val android: com.

public val AuthResult.android: com.google.firebase.auth.AuthResult get() = android

public actual class AuthResult internal constructor(internal val android: com.google.firebase.auth.AuthResult) {
public actual class AuthResult(internal val android: com.google.firebase.auth.AuthResult) {
public actual val user: FirebaseUser?
get() = android.user?.let { FirebaseUser(it) }
public actual val credential: AuthCredential?
get() = throw NotImplementedError()
public actual val additionalUserInfo: AdditionalUserInfo?
get() = throw NotImplementedError()
}

public actual class AdditionalUserInfo {
public actual val providerId: String?
get() = throw NotImplementedError()
public actual val username: String?
get() = throw NotImplementedError()
public actual val profile: Map<String, Any?>?
get() = throw NotImplementedError()
public actual val isNewUser: Boolean
get() = throw NotImplementedError()
}

public val AuthTokenResult.android: com.google.firebase.auth.GetTokenResult get() = android
Expand Down