Logic for Storyboard initial View Controller not working

I’m having a problem setting the initial view controller programmatically. I can set it, but the when I run the app, the main controller always comes up when the login controller should be, and the compiler finds nil. It seems only the

if Auth.auth().currentUser != nil {

function is working. It always defaults to the view controller I have inside of it. Even when I start the second function with “else{” it still doesn’t work…

I’ve tried two ways to do this: Using the UserDefaults for the User’s username(comparing the string to nil) and Firebase auth. Here is my code:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {            
        FirebaseApp.configure() 

   self.window = UIWindow(frame: UIScreen.main.bounds)
    if Auth.auth().currentUser != nil {
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let initialViewController = storyboard.instantiateViewController(withIdentifier: "MainFeedNavigation")
       self.window?.rootViewController = initialViewController

    }
    
    if Auth.auth().currentUser == nil  {
    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let initialViewController = storyboard.instantiateViewController(withIdentifier: "TitleScene")
    self.window?.rootViewController = initialViewController
}
    self.window?.makeKeyAndVisible()

        return true
    }

I’ve played around with using UserDefaults instead of the Auth() method, but that doesn’t work either. Any ideas?
Thanks,
Jack

Hi @jderbs,
What does your Auth object do? and your storyboard identifiers, maybe if you had a sample/cut down project someone could have a look and help you (if you haven’t already found a solution to this)

cheers,

Jayant