Realm will not work when logging in after a logout

I have a kmm app on swiftui and kotlin.

My problem is that whenever I try to do a logout and then logging in back, the realm sync will not open or work. The realm will work only if I close the app and re-open the app.
Also, when starting the app on the login page, everything works fine, so the problem its when doing the logout.

On the logout I do a reset of the repo, I re-initialize the object:

func doLogout(){
        repo.doLogout(){error in
            SingletonRepo.reset()
            UserDefaults.standard.set(false, forKey: "isLogin")
            isLoginShown = true
        }
    }

the SingletonRepo with the reset method:

class SingletonRepo{

    static var shared = RealmRepo()
    
    private init() { }
    
    static func reset() {
            shared = RealmRepo()
        }

The reset will re-initialize the shared Kotlin RealmRepo(). I do this for the next user to have a new Realm Repo instance.

Is this the correct flow?
Shouldnt I reset the realm repo when doing the logout?
Should I close it? Should I close the repo and then reset it?
What is the correct flow?

Thank you for your time!

Why are you using UserDefaults for that and what does the actual login and logout code look like? The code in the question is a big vague so it’s hard to get a feel for what you’re attempting to do.

The userdefaults are related to the iOS, it does not affect of the flow.
I do a simple realm.login and realm.logout.

Understood. However, the code in the question doesn’t have a lot of meaning without more context.

We don’t know what SingletonRepo or RealmRepo is or does or if it needs to be ‘reset’ - why do you want to reset it? What does ‘close the repo’ mean?

Generally speaking when you log out of Realm, well, you’re logged out… and it’s ready for the same or different user to log in. There’s really no ‘resetting’ or ‘closing’ needed.

You also don’t generally need to store anything in UserDefaults in regards to logging in our out - maybe there’s something for your use case though.