Fatal error: Invalid state: A login callback was received, but no login request was sent

This error occurs when trying to SignIn with Apple with Swift :

Fatal error: Invalid state: A login callback was received, but no login request was sent

I followed this guide by Firebase. The only thing I had to do different is:

let credential = OAuthProvider.credential(withProviderID: "apple.com", idToken: idTokenString, rawNonce: nonce, accessToken: nil)

instead of

let credential = OAuthProvider.credential(withProviderID: "apple.com",
                                            IDToken: idTokenString,
                                            rawNonce: nonce)

as the code form the documentation gives an error.

Here is my method:

func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) {
  if let appleIDCredential = authorization.credential as? ASAuthorizationAppleIDCredential {
    guard let nonce = currentNonce else {
      fatalError("Invalid state: A login callback was received, but no login request was sent.")
    }
    guard let appleIDToken = appleIDCredential.identityToken else {
      print("Unable to fetch identity token")
      return
    }
    guard let idTokenString = String(data: appleIDToken, encoding: .utf8) else {
      print("Unable to serialize token string from data: (appleIDToken.debugDescription)")
      return
    }
//        // Initialize a Firebase credential.
//        let credential = OAuthProvider.credential(withProviderID: "apple.com",
//                                                  IDToken: idTokenString,
//                                                  rawNonce: nonce)


 let credential = OAuthProvider.credential(withProviderID: "apple.com", idToken: idTokenString, rawNonce: nonce, accessToken: nil)

    // Sign in with Firebase.
    Auth.auth().signIn(with: credential) { (authResult, error) in
        if (error != nil) {
        // Error. If error.code == .MissingOrInvalidNonce, make sure
        // you're sending the SHA256-hashed nonce as a hex string with
        // your request to Apple.
            print(error!.localizedDescription)
        return
      }
      // User is signed in to Firebase with Apple.
      // ...
    }
  }
}

Here is my Git-Project. To reproduce the error just run the app and tap on the appleButton.

Source: Ios