When the user opens the app, if auth.currentuser isn't null, then I need to query the user's username. I think a query listener makes sense because I don't want to keep pinging the server every time some code asks for the username. I looked at the Firebase docs they provide this example:
val docRef = db.collection("cities").document("SF")
docRef.addSnapshotListener { snapshot, e ->
if (e != null) {
Log.w(TAG, "Listen failed.", e)
return@addSnapshotListener
}
val source = if (snapshot != null && snapshot.metadata.hasPendingWrites())
"Local"
else
"Server"
if (snapshot != null && snapshot.exists()) {
Log.d(TAG, "$source data: ${snapshot.data}")
} else {
Log.d(TAG, "$source data: null")
}
}
However, I was advised to try to use as little client side code as possible to optimize security, so the aforementioned example worries me. Is it possible to use a query listener to listen to a server side function that can output the username so that I can still take advantage only running the query once, i.e. saving the username to the client cache?