NEW: My new book Pro SwiftUI is out now – level up your SwiftUI skills today! >>

SOLVED: Navigate to New View after login

Forums > iOS

Hi I am trying to naviagte to a new view after firebase auth using an if statment but am unable to. It is currently printing the users id from firebase in the concole after authenication, but i would like it to navigate to my home screen. Any help would be much appricated. Current code for the button:

                    Auth.auth().signIn(withEmail: email, password: password){
                        authResult, error in
                        if let error = error{
                        if let authResult = authResult{

                }label: {
                    Text("Sign in")
                        .frame(maxWidth: .infinity)
                        .background(RoundedRectangle(cornerRadius: 10)
                            .fill(Color(red: 206/255, green: 170/255, blue: 77/255)


Hi I have found a fix to this for anyone else who is looking for one these are the steps:

  1. Make sure your login view is in a var content: some View
  2. Make a var body: some View and add in if userisloggedIn {Calendar()}else{content}
  3. Add a @State private var userisloggedIn = false
  4. Add in if authResult != nil {userisloggedIn.toggle()}
  5. Then Test!!


Hacking with Swift is sponsored by Judo

SPONSORED Let’s face it, SwiftUI previews are limited, slow, and painful. Judo takes a different approach to building visually—think Interface Builder for SwiftUI. Build your interface in a completely visual canvas, then drag and drop into your Xcode project and wire up button clicks to custom code. Download the Mac App and start your free trial today!

Try now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.