Amissi
Amissi

Reputation: 217

How do I stop a segue from happening in Swift?

I have a login scene that segues to another scene when the user clicks the login in button, but, I'm trying to stop it from happening when the user email and password is incorrect. I'm using Firebase and this function below checks to see whether the username and password are correct, but I want to stop the segue from happening when it's not correct.

 func userLogin (user: String!, pass: String!){
    ref.authUser(user, password: pass,
                 withCompletionBlock: { error, authData in
                    if error != nil {
                        print("user account doesnt exist")
                    } else {
                        print("You're logged in Fam")
                    }
    })
}

Upvotes: 1

Views: 3481

Answers (1)

JZAU
JZAU

Reputation: 3567

Try this:

override func shouldPerformSegueWithIdentifier(identifier: String, sender: AnyObject?) -> Bool {
    if password incorrect {
        return false
    }else {
        return true
    }
}

or preform segue after auth successfully:

func userLogin (user: String!, pass: String!){
ref.authUser(user, password: pass,
             withCompletionBlock: { error, authData in
                if error != nil {
                    print("user account doesnt exist")
                } else {
                    print("You're logged in Fam")
                    performSegueWithIdentifier("Your identifier", sender: AnyObject?)
                }
})

}

Upvotes: 8

Related Questions