Switch View - Facebook Auth

Hi
How can i switch view after the user has logged in with facebook. Im using Facebook auth with firebase.

Thanks
Nick

Hello it should work the same as our firebase custom login video on youtube check it out and use it as reference

@fuerte.francis
Hi, if that is so, it would be great. Do you by any chance have the link for the video?

Thanks

Hello, it would be this video

Hi, so i have actually already seen that video.
And for as far as i can tell he is using storyboard and not SwiftUI (im using swiftUI)

This is the code he uses for the transition between the two views, but how can i change it so i can use it for SwiftUI? @fuerte.francis

func transitionToHome() { let homeViewController = storyboard?.instantiateViewController(identifier: Constants.Storyboard.homeViewController) as? HomeViewController view.window?.rootViewController = homeViewController view.window?.makeKeyAndVisible() }

oh you are doing it in SwiftUI, i think it would be better to use a different one regarding NavigationViews/NavigationController
but we don’t have a video on that sadly, maybe check out some tutorials on a quick google search

@fuerte.francis ah okay i see. But the thing is that i have to some degree managed to change the view when logged in and logged out. This is the code i use in scenedelegate. The problem is that i have to manually reload the app before it changes view. How can i fix it, so i dont have to manually reload it?
The code i use for facebook auth can be seen down below, after the SceneDelegate

class SceneDelegate: UIResponder, UIWindowSceneDelegate {
    @ObservedObject var loginScreen = LoginView.Coordinator()

    var window: UIWindow?
    
    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
 
        if let windowScene = scene as? UIWindowScene {
            let window = UIWindow(windowScene: windowScene)
            if (self.loginScreen.token != nil){ window.rootViewController = UIHostingController(rootView: ContentView())}
            else {window.rootViewController = UIHostingController(rootView:LoginView().frame(width: 250, height: 50)
            .cornerRadius(10) )}
            self.window = window
            window.makeKeyAndVisible()
            
        }
    }
}




struct LoginView : UIViewRepresentable {

func makeCoordinator() -> LoginView.Coordinator {
    return LoginView.Coordinator()
}


func makeUIView(context: UIViewRepresentableContext<LoginView>) -> FBLoginButton {
    let button = FBLoginButton()
    button.permissions = ["email"]
    button.delegate = context.coordinator
    return button
}

func updateUIView(_ uiView: FBLoginButton, context: UIViewRepresentableContext<LoginView>) {
    
}

class Coordinator : NSObject, ObservableObject,LoginButtonDelegate{
    @Published var  token = AccessToken.current
    
    
    
    func loginButtonDidLogOut(_ loginButton: FBLoginButton) {

        self.token = AccessToken.current
        try! Auth.auth().signOut()
        print("Did logout - From loginButtonDidLogOut")
        
    }
    
    func loginButton(_ loginButton: FBLoginButton, didCompleteWith result: LoginManagerLoginResult?, error: Error?) {
        
        if error != nil  {
            print((error?.localizedDescription)!)
            return
        }
        
        if AccessToken.current != nil {
            let credential = FacebookAuthProvider.credential(withAccessToken: AccessToken.current!.tokenString)
            Auth.auth().signIn(with: credential) {(res ,  er) in
                self.token = AccessToken.current
                
                if er != nil{
                    print((er?.localizedDescription)!)
                    return
                }
                
                print("SUCCES! ")
    
            }
        }
    }
}

}

i guess it would be better to just open a “common” screen, like a landing page (login page maybe?) where theres a background thread checking if you are logged in or not, which will then auto redirect you to the appropriate screen

Im sry i dont understand what that means. Can you explain it a bit more? Im somewhat new to Swift