이메일을 내려주기도 하고, 내려주지 않기도 한다 ?

카카오 소셜 로그인은 어찌저찌 만들었는데, 애플 소셜 로그인을 구현하려다가 자꾸 안돼서 왜 그러는지 디버깅 해보았다

먼저 코드

func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) {
        
    guard let credential = authorization.credential as? ASAuthorizationAppleIDCredential
    else { return }
    
    let userIdentifier = credential.user
    let appleProvider = ASAuthorizationAppleIDProvider()
    appleProvider.getCredentialState(forUserID: userIdentifier) { state, err in
        
        guard err == nil
        else {
            print("❌ \\(String(describing: err)) ❌")
            return
        }
        
        switch state {
        case .authorized:
            guard let email = credential.email
            else {
                print("❌ Cannot get email ❌")
                return
            }
            let request = SignUpRequestDTO(
                platformType: .apple,
                email: email,
                password: "",
                nickname: ""
            )
        case .notFound:
            print("❌ User not found ❌")
        case .revoked:
            print("❌ User revoked ❌")
        default:
            print("❌ Unknown error: \\(state) ❌")
        }
    }
}

그리고 안되는 이유

Untitled

이메일을 가져올 수 없다는데 …?

이렇게 되는 이유가 구글링 해보니

Untitled

처음 Sign in with Apple 을 할 때에만 이메일을 제공하지, 그 이후 이미 있는 유저 값을 불러올 때에는 제공하지 않는다고 한다

그래서 guard 문에서 막힌듯 …