KSessionManager

class KSessionManager(store: KTokenStore, providedScope: CoroutineScope? = null)(source)

Generic session manager for token-based authentication.

Constructors

Link copied to clipboard
constructor(store: KTokenStore, providedScope: CoroutineScope? = null)

Properties

Link copied to clipboard
val accessToken: StateFlow<String?>

Current access token. null means unauthenticated.

Link copied to clipboard
val isReady: StateFlow<Boolean>

true once tokens have been hydrated from the store.

Link copied to clipboard
val refreshToken: StateFlow<String?>

Current refresh token. null means unauthenticated.

Functions

Link copied to clipboard
suspend fun awaitReady(): Boolean

Waits until the initial token load is complete.

Link copied to clipboard
suspend fun clearSession()

Clears all stored tokens and resets the StateFlows to null.

Link copied to clipboard
fun close()

Cancels the CoroutineScope used by this manager, if it was created internally.

Link copied to clipboard

Returns true if an access token is currently held in memory.

Link copied to clipboard
suspend fun saveTokens(accessToken: String?, refreshToken: String?)

Persists both tokens and updates the StateFlows.

Link copied to clipboard
suspend fun updateAccessToken(token: String?)

Updates only the access token while keeping the refresh token consistent.

Link copied to clipboard
suspend fun updateRefreshToken(token: String?)

Updates only the refresh token while keeping the access token consistent.