Ok been having a dig around for too long now and can’t find a solution to this. Either I’m googling the wrong terms or the info doesn’t exist (more likely the former!)
In swift I used the below code in the SceneDelegate func scene… to detect if there is current user and then redirect them to a different view
let currentUser = Auth.auth().currentUser
if currentUser != nil {
let board = UIStoryboard(name: "Main", bundle: nil)
let home = board.instantiateViewController(identifier: "home") //as! UITabBarController
window?.rootViewController = home
}
How do you achieve this behaviour in SwiftUI. I’ve managed to achieve it by publishing this bool in my LoginViewModel (which I’m also using to detect when a user is successfully logged in after completing the login form)…
@Published var isLoggedIn: Bool = false // Track login status
Then in my ContentView (the first view that loads) I’m observing that bool and added this to the navigation stack
.onAppear {
// Check if the user is already logged in
if Auth.auth().currentUser != nil {
viewModel.isLoggedIn = true
}
}
.fullScreenCover(isPresented: $viewModel.isLoggedIn) {
TabBarView()
}
Which does work, but only after fully loading the welcome screen and visibly transitioning the user to my TabBarView. How can I do this so the user goes straight to the TabBarView and never seeing the ContentView.
My first swiftUI app, so likely full noob error. Any help appreciated.