Skip to content

Commit

Permalink
Add fallback for empty userId by using null in Firestore query
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-sneh-s committed Jan 10, 2025
1 parent 6391d5e commit ac43e50
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ class ApiUserService @Inject constructor(

suspend fun getUser(userId: String): ApiUser? {
return try {
val user = userRef.document(userId).get().await().toObject(ApiUser::class.java)
val user = userRef.document(userId.takeIf { it.isNotBlank() } ?: "null").get().await()
.toObject(ApiUser::class.java)
when {
user == null -> null
currentUser == null || user.id != currentUser.id -> user
Expand Down Expand Up @@ -107,7 +108,7 @@ class ApiUserService @Inject constructor(
last_name = account?.familyName ?: "",
provider_firebase_id_token = firebaseToken,
profile_image = account?.photoUrl?.toString() ?: firebaseUser?.photoUrl?.toString()
?: ""
?: ""
)
userRef.document(uid).set(user).await()
val sessionDocRef = sessionRef(user.id).document()
Expand Down

0 comments on commit ac43e50

Please sign in to comment.