title: sign up flow segues to the wrong view controller and doesn't write to firestore either
body: <p>So my goal is to have the correct user sign up and be shown the correct segue as well as the user info be written to Firestore. So I have a basic sign up function that gets triggered when the sign up button is pressed:</p>
  <pre><code>@IBAction func schoolSignupPressed(_ sender: UIButton) {
      let validationError = validateFields()
      let schoolName = schoolNameTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
      let schoolEmail = schoolEmailTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
      let schoolPassword = schoolPasswordTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
      let schoolID = schoolIDTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
      let schoolDistrict = schoolDistrictTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
      let dateCreated = Date()
      
      if validationError != nil {
          return
      }
      
      Auth.auth().createUser(withEmail: schoolEmail, password: schoolPassword) { (result, error) in
          guard let signUpError = error?.localizedDescription else { return }
          
          guard error == nil else {
              self.showAlert(title: &quot;Error Signing Up&quot;, message: &quot;There was an error creating the user. \(signUpError)&quot;)
              return
          }
          
          let db = Firestore.firestore()
          guard let result = result else { return }
          db.document(&quot;school_users/\(result.user.uid)&quot;).setData([&quot;school_name&quot;:schoolName,
                                                                  &quot;school_id&quot;:schoolID,
                                                                  &quot;emailAddress&quot;: result.user.email ?? schoolEmail,
                                                                  &quot;remindersPushNotificationsOn&quot;: true,
                                                                  &quot;updatesPushNotificationsOn&quot;: true,
                                                                  &quot;schoolDistrict&quot;:schoolDistrict,
                                                                  &quot;time_created&quot;:dateCreated,
                                                                  &quot;userID&quot;: result.user.uid],
                                                                 merge: true) { (error) in
              guard let databaseError = error?.localizedDescription else { return }
              guard error == nil else {
                  self.showAlert(title: &quot;Error Adding User Info&quot;, message: &quot;There was an error adding the user info. \(databaseError)&quot;)
                  return
              }
          }
          
          let changeRequest = result.user.createProfileChangeRequest()
          changeRequest.displayName = schoolName
          changeRequest.commitChanges { (error) in
              guard error == nil else {
                  return
              }
              print(&quot;School Name Saved!&quot;)
          }
          DispatchQueue.main.asyncAfter(deadline: .now()+1) {
              self.performSegue(withIdentifier: Constants.Segues.fromSchoolSignUpToSchoolDashboard, sender: self)
          }
      }
  }
  </code></pre>
  <p>This is the sign up function for the 'school' user, but the 'student' user is essentially the same thing just different fields and of course a different segue destination. Now maybe like a day ago or 2, I was testing this function out and it was working completely fine the user was succesfully signed up, the user info was written to firestore, the correct view controller was displayed, the only difference was I had some <code>DispatchGroup</code> blocks within the function because when i was running the method in TestFlight, there would be a couple of bugs that would crash the app.</p>
  <p>So I figured since everything was working fine in the simulator, I archive the build, upload it to TestFlight and wait for it to be approved. It got approved last night and I ended up testing it out on my phone this morning to see it again, now when I try to sign up as either a school user or a student user, it segues to the wrong view controller every time and no info gets written to firestore, the user just gets saved in Firebase Auth and that is not the outcome I expect in my app.</p>
  <p>I've checked the segue identifiers, I've checked the connections tab, and even though it was working amazing 24 hours ago, I still checked it all. I'm trying my best to really appreciate what Apple does for developers but I'm really starting to grow a hatred towards TestFlight, everything I do and run in the simulator works fantastic on Xcode, as soon as I run it in TestFlight, everything just goes out the window. I hate these types of bugs because you genuinely don't know where the issue is stemming from simply because you've used, if not very similar, the <strong>exact</strong> same method in every other previous situation.</p>
  <p>The login process works fine on both student and school user, I'll show an example of the school user login method:</p>
  <pre><code>@IBAction func loginPressed(_ sender: UIButton) {
      
     let validationError = validateFields()
      
      let email = schoolEmailTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
      let password = schoolPasswordTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
      
      if validationError != nil {
          return
      } else {
  
          Auth.auth().signIn(withEmail: email, password: password) { (result, error) in
              guard let signInError = error?.localizedDescription else { return }
              let group = DispatchGroup()
              group.enter()
              guard error == nil else {
                  self.showAlert(title: &quot;Error Signing In&quot;, message: &quot;There was an issue trying to sign the user in. \(signInError)&quot;)
                  return
              }
              group.leave()
              
              group.notify(queue: .main) {
                  DispatchQueue.main.asyncAfter(deadline: .now()+1) {
                      self.performSegue(withIdentifier: Constants.Segues.fromSchoolLoginToSchoolEvents, sender: self)
                  }
              }
          }
      }
  }
  </code></pre>
  <p>Pretty much the same for student users. If anyone can point out possible issues for this bug in the first code snippet that would be amazing. Thanks in advance.</p>