title: Swift login session rootController UserDefaults error
body: <p>i try to make login session for login, and just any other login session when user is logged in they go straight to Main Menu, and i havent logged in yet but i go straigth to main menu, any help? </p>
  
  <p>here is my code : </p>
  
  <pre><code>  func Login() {
  
       let Email = EmailField.text!
       let Pass = PasswordField.text!
  
       let api = "http://\(GlobalVariable.ip):7909/api/loginApi? Email=\(Email)&amp;Password=\(Pass)"
      print(api)
  
      guard let JsonUrl = URL(string: api) else { return }
      URLSession.shared.dataTask(with: JsonUrl) { (data, response, error)in
          guard let data = data else { return }
  
              if let success = try?   JSONDecoder().decode([LoginSuccess].self, from: data).first{
  
                  GlobalVariable.UserId = String(success.id)
                  GlobalVariable.UserIdProjectSum =   String(success.id)
                  GlobalVariable.UserIdDashboard = String(success.id)
                  GlobalVariable.Email = String(success.email)
                  GlobalVariable.Name = String(success.name)
  
                  UserDefaults.standard.set(true, forKey: "IsLog")
                  UserDefaults.standard.synchronize() //this is where i put the userDefaults 
  
                  DispatchQueue.main.async {
                      self.appDelegate.loginSeque()
                  }
              } else if let failure = try?   JSONDecoder().decode([LoginFailed].self, from: data).first {
  
                  //ini buat popup kalo login gagal
                  DispatchQueue.main.async {
                      let action = UIAlertAction(title: "ok", style:   .default, handler: nil)
                      let alert = UIAlertController(title: "Login   Fail...", message: "Incorect Email/Password", preferredStyle: .alert)
                      alert.addAction(action)
                      self.present(alert, animated: true, completion:    nil)
                  }
             }
          }.resume(). 
  
  
  
  
        //heres the app delegate
  
  
  
             func application(_ application: UIApplication,   didFinishLaunchingWithOptions launchOptions: [.     UIApplication.LaunchOptionsKey: Any]?) -&gt; Bool {
  
            LoginSession()
            return true
           }
  
           func LoginSession() {
  
      if UserDefaults.standard.value(forKey: "IsLog") != nil {
          let vc = UIStoryboard(name: "Main", bundle: Bundle.main).instantiateViewController(withIdentifier: "Main")
          let navVc = UINavigationController(rootViewController: vc)
          let share = UIApplication.shared.delegate as? AppDelegate
          share?.window?.rootViewController = navVc
          share?.window?.makeKeyAndVisible()
      }else{
          let vc = UIStoryboard(name: "LogIn", bundle: Bundle.main).instantiateViewController(withIdentifier: "Login")
          let navVc = UINavigationController(rootViewController: vc)
          let share = UIApplication.shared.delegate as? AppDelegate
          share?.window?.rootViewController = navVc
          share?.window?.makeKeyAndVisible()
              }
  
            }
  
  
     func loginSeque() {
  
  
      let storyboard = UIStoryboard(name: "Main", bundle: nil)
  
      let navbar = storyboard.instantiateViewController(withIdentifier: "navBar")
      window?.rootViewController = navbar
  
       }
  </code></pre>
  
  <p>so the error is i keep getting to main menu even i havent log in yet, maybe i did something wrong in my code or i make mistakes in my algorithm? thanks for the help:)</p>