London Escorts sunderland escorts 1v1.lol unblocked yohoho 76 https://www.symbaloo.com/mix/yohoho?lang=EN yohoho https://www.symbaloo.com/mix/agariounblockedpvp https://yohoho-io.app/ https://www.symbaloo.com/mix/agariounblockedschool1?lang=EN
-7.3 C
New York
Sunday, February 2, 2025

ios – How do I take person to root file on completion of a operate?


In my app I’ve a button to log the person out. This runs an API that deletes their session and in addition it takes their session key out of person defaults.

This implies they can not entry API’s within the app. However after the sign off has occurred, I need the person to be taken to the Register() view. In my ContentView(), I’ve an if assertion that checks if they’ve a session key, if the person does not, Register() is introduced.

I have to make it in order that every time there is no such thing as a session key, Register() is introduced. Right here is my code:

struct ContentView: View {
    
    var physique: some View {
        
        let defaults = UserDefaults.normal
        if let keyString = defaults.string(forKey: "sessionKey") {
            
            MainPage()
                                    
        } else {
            Register()
                        
        }
    }
}
struct LogOutView: View {
    
    @StateObject var loginModel = LoginViewModel()
    
    var physique: some View {
                                
        VStack {
                                    
            Button(motion: {
                print("Log Out Tapped...")
                let defaults = UserDefaults.normal
                let keyString = defaults.string(forKey: "sessionKey") ?? ""
                
                loginModel.logOut(key: keyString ) { success in
                    
                    if success {
                        // Efficiently logged out, take away the "key" from UserDefaults
                        UserDefaults.normal.removeObject(forKey: "sessionKey")
                    }
                }
                
            }, label: {
                
                Textual content("Log Out")
            })
        }
    }
}

If ContentView ran once more after the sign off I’d haven’t any issues however I’m not certain that may be a good technique.

How can I do that?

Tried NavigationLinks, however this will trigger issues within the customers navigation stream

Related Articles

Social Media Auto Publish Powered By : XYZScripts.com