Search code examples
iosswiftxcodeauthenticationsegue

Should I use a segue to move between a sign up screen and the rest of my app


I have created a login/sign up screen for my application using firebase and now when a user successfully logs in or signs up I want to transfer them to the rest of my application.

I am currently using a segue to do this, so whenever a user enters information that is valid in the firebase database, or whenever they sign up and create their information in the database, a segue takes them to the tab bar controller of the app itself.

I am new to Xcode and don't know if this is a safe thing to do or not. For example, does this create a danger of users being able to get into my actual app without being properly identified in the database if they somehow manipulate the segue into taking them there? I don't want any dangers like this in my app and want to know if there is any other way in which this could, or maybe should, be done.

Thank you very much.


Solution

  • Using a segue is fine, but you might want to consider doing it in reverse.

    If the user isn't signed up, when the application is launched, present a modal sign up viewcontroller from the main application viewcontroller. Once they've entered their info and have been validated, do an unwind segue to return to the main application screen.

    The reason to do it this way is that it frees the memory used by the login/signup screen. The way you are doing it keeps the login/signup VC in memory the whole time the app is running.

    Your main viewController in your UITabViewController would look like this:

    class FirstViewController: UIViewController {
    
        var loggedIn = false
    
        override func viewDidLoad() {
            super.viewDidLoad()
            // Do any additional setup after loading the view, typically from a nib.
        }
    
        override func viewDidAppear(_ animated: Bool) {
            super.viewDidAppear(animated)
    
            if !loggedIn {
                self.performSegue(withIdentifier: "LogInSignUp", sender: self)
            }
        }
    
        // This is the target of the unwind segue        
        @IBAction func finishedLoggingIn(_ segue: UIStoryboardSegue) {
            loggedIn = true
            print("logged in and ready to go!")
        }
    
    }
    

    If you uncheck the Animates checkbox in the Attributes Inspector for the "LogInSignUp" segue, the login screen will appear immediately without animation, but it will still drop down once the login is complete (during the unwind segue).