GO FURTHER, FASTER: Try the Swift Career Accelerator 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:

Button{
                    Auth.auth().signIn(withEmail: email, password: password){
                        authResult, error in
                        if let error = error{
                            print(error)
                            return
                        }
                        if let authResult = authResult{
                            print(authResult.user.uid)
                        }
                    }

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

3      

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!!

3      

Hacking with Swift is sponsored by Essential Developer.

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until September 29th.

Click to save your spot

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

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

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.