Session & User State
The signed-in user, an auth token, the active profile — state that's scoped to a login session
rather than the app's durable settings. Keeping it in its own collection keeps it
separate from data that should survive a logout.
@Serializable
data class Session(
val userId: String,
val displayName: String,
val authToken: String,
)
val sessionStore = Documents.collection("session")
val session = sessionStore.document<Session>("current")
// sign in
session.set(Session(userId = "u_42", displayName = "Mara", authToken = "…"))
// react to sign-in / sign-out anywhere in the UI
session.flow().collect { current ->
isSignedIn = current != null
}
Logging out deletes the session document — there is no separate "clear the whole collection"
call in the public API, so sign-out is an explicit delete() on each document that
should end with the session:
fun signOut() {
session.delete()
}
See Opening Documents for when to reach for a named collection versus the default store, and keep in mind the single-process constraint that applies to every store, including this one.