MaxKrissigo MaxKrissigo - 2 months ago 21
Swift Question

Firebase 3.6.0 (Auth) - Detecting the specific error - Swift 3.0

I'm trying to work out how to detect a certain error. Say the login failed, I want to check if the error was say the account entered doesn't exist, and then tell the viewer that. Same goes with all of the other errors if possible.

In Parse I would check if the error.code was equal to a certain number, not sure if it's the same or anything similar to Firebase.

Any help is appreciated!

Answer

Use this:-

if let errCode = FIRAuthErrorCode(rawValue: err!._code) {

                switch errCode {
                case .errorCodeInvalidEmail:
                    print("invalid email")
                case .errorCodeEmailAlreadyInUse:
                    print("in use")
                default:
                    print("Other error!")
                }

            }

Where err is the received error from firebase

Comments