Log out happens before db operation Kotlin KMM Realm Mongodb

I have a kmm app, and I have a shared repository in Kotlin. I have a login that does the normal login to Realm MongoDb and add a FCM key. I have also a logout method that should remove first the FCM token and then do the logOUT() from Realm MongoDB

My logOut method:

suspend fun doLogout(token: String) {
    val userId = appService.currentUser?.id

    realm.write {

            var user = query<UserInfo>("_id = $0", userId).first().find()
            if (user != null) {
                val productIndex =
                    user.FCMToken.withIndex().findLast { it.value == token }!!.index

                user = findLatest(user)!!.also {


I think what happens is that the logout happens before the DB change.

How can I do the logout after the db change is completed?