Skip to content
This repository was archived by the owner on Oct 22, 2022. It is now read-only.

Latest commit

 

History

History
79 lines (56 loc) · 1.71 KB

File metadata and controls

79 lines (56 loc) · 1.71 KB

Backdraft 🔥

Kotlin Coroutine Extensions for Firebase 🔥

Experimental!

This is still a work in progress, and relies on Kotlin's experimental Flow objects. API's may change as needed. Proceed with caution.

Firebase Auth

Auth State

You can observe the current auth state by collecting updates on the AuthState Flow:

firebaseAuth.authStateFlow.collect { authState ->
    Log.d("Example", "User changed to: ${authState.currentUser?.uid}")
}

Current User

For convenience, the current user can be observed directly with the userFlow extension:

firebaseAuth.currentUser.collect { currentUser ->
    Log.d("Example", "User changed to: ${currentUser?.uid}")
}

ID Token

Firebase's ID Token can be observed with the idTokenFlow extension:

firebaseAuth.idTokenFlow.collect { tokenResult ->
    Log.d("Example", "ID Token changed to: ${tokenResult?.token}")
}

Firestore

Collection Snapshots

Firestore collections can be observed with the snapshotFlow extension:

firebaseFirestore
    .collection("users")
    .snapshotFlow
    .collect { snapshot ->
        Log.d("Example", "New data for collection documents. Size: ${snapshot?.documents?.size}")
    }

Document Snapshots:

Firestore documents can be observed with the snapshotFlow extension:

firebaseFirestore
    .collection("users")
    .document("id-123")
    .snapshotFlow
    .collect { snapshot ->
        Log.d("Example", "New data for user, ID: ${snapshot?.id}")
    }

Tasks

Any Task<T> object can be suspended for a result using .await():

val authResult = firebaseAuth.createUserWithEmailAndPassword("johndoe@example.com", "notsecure").await()