TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

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 String Catalog.

SPONSORED Get accurate app localizations in minutes using AI. Choose your languages & receive translations for 40+ markets!

Localize My App

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.