fun flowFromSigIn(userName: String, password: String): Flow = callbackFlow { val successCallback = Consumer { value -> try { if (value.isSignInComplete) { logger.debug("$value") connectionSession.username = AWSMobileClient.getInstance().username AWSMobileClient.getInstance().userAttributes?.let { // iterate attributes it.forEach { (attributeName, attributeValue) -> // check email if (attributeName == "email") { logger.debug("write email into keystore" ) // do stuuf with attributeValue } } if (thingId != null) { sendBlocking(true) } else { sendBlocking(false) } } } else { sendBlocking(false) } } catch (e: Exception) { logger.error("AuthQuickStart", e) } } val errorCallback = Consumer { value -> try { sendBlocking(false) } catch (e: Exception) { logger.error("AuthQuickStart", e) } } Auth.signIn(userName, password, successCallback, errorCallback) logger.debug("AuthQuickStart") awaitClose { } }