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:

                    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 Superwall.

SPONSORED Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.

Learn More

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.