checkUser

fun checkUser()

Checks whether the API user exists and, if not, creates it — then advances to createApiKey.

Uses kotlinx.coroutines.flow.flatMapLatest to flatten the check → create sequence into a single flow without nesting .collect calls:

  • checkApiUser Success → passes through; the outer .collect calls createApiKey.

  • checkApiUser Error → switches the active inner flow to createApiUser; the outer .collect calls createApiKey once that succeeds.

  • Loading from either call → passed through to the outer collect and ignored (no UI state is managed by this ViewModel).

The bootstrap sequence does not repeat: if createApiUser also fails, the error is logged and the chain stops — isBootstrapComplete is set to true to unblock any waiting observers. The user will remain uncredentialled until checkUser is called again.