Sign In with Apple No Credential Available

394 Views Asked by At

I am trying to implement a Sign In with Apple button to sign users in or create them an account depending on if they're new or not. When using my own device I can log into any account just fine using the 'Sign In with Apple' button, but when trying with a different device I get this error: FAILED: The operation couldn’t be completed. No credentials available for login.

I'm unsure what this really means or how to fix it. Here's my code:

@objc private func appleSignInPressed() {
    let provider = ASAuthorizationAppleIDProvider()
    let request = provider.createRequest()
    request.requestedScopes = [.email, .fullName]
            
    let requests = [request, ASAuthorizationPasswordProvider().createRequest()]
    let controller = ASAuthorizationController(authorizationRequests: requests)
    controller.delegate = self
    controller.presentationContextProvider = self
    controller.performRequests()
}



extension WelcomeViewController: ASAuthorizationControllerDelegate {
    func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) {
        switch authorization.credential {
        case let passwordCredential as ASPasswordCredential:
            let username = passwordCredential.user
            let password = passwordCredential.password
            viewModel.didTouchLoginButton(with: username, and: password, feeds: [], referralLink: nil)
        case let credentials as ASAuthorizationAppleIDCredential:
            
            let givenName = credentials.fullName?.givenName ?? "user"
            guard let email = credentials.email else {
                return
            }
            print(givenName + " " + email)
        default:
            startSignUpFlow()
        }
    }
    
    func authorizationController(controller: ASAuthorizationController, didCompleteWithError error: Error) {
        print("FAILED: \(error.localizedDescription)")
    }
}
0

There are 0 best solutions below