This is how users navigate through my app:

  1. Enter a phone number
  2. Enter verification number (This allows them access to my Firestore)
  3. Enters a username
  4. Now they're in the main app

Pretty straightforward however the problem is if the app crashes (for whatever reason) or closes when they are entering the username, they are still technically signed in to my Firestore.

It's a problem because I programmed the app such that when the user reopens the app, they immediately go to the main screen (I created an app manager to handle this). If they close the app (or if it crashes) before they enter a username, they can go right to the main screen without a username.

I've made several different attempts in the applicationWillTerminate method to track which view controller the user is in, sign out so that when the user open the app again, my App Manager says, Auth.auth().currentUser == nil and goes to the initial view controller to start the registration process again.

var viewController : UIViewController?
        var vc = UsernameViewController()

        if viewController == vc {

            let firebaseAuth = Auth.auth()
                        do {
                            try firebaseAuth.signOut()
                        } catch let signOutError as NSError {
                            print ("Error signing out: %@", signOutError)
                        }

I expect the user who did not get a chance to create a username because the app closed or crashed to to return to the initial view controller rather than the main screen of the app.

I am currently experiencing the opposite.

0 Answers