appleAuthRequestResponse为fullName和电子邮件返回null



我很困惑为什么在用户身份验证成功后,下面的代码片段在控制台中显示电子邮件为null和fullName。我仔细阅读了文件,并尽了一切可能。如有任何帮助,我们将不胜感激。

async function onAppleButtonPress() {
// performs login request
const appleAuthRequestResponse = await appleAuth.performRequest({
requestedOperation: AppleAuthRequestOperation.LOGIN,
requestedScopes: [AppleAuthRequestScope.EMAIL, AppleAuthRequestScope.FULL_NAME],
});
//api getting current state of the user
const credentialState = await appleAuth.getCredentialStateForUser(appleAuthRequestResponse.user);

if (credentialState === AppleAuthCredentialState.AUTHORIZED) {
// user is authenticated
console.log("email is",appleAuthRequestResponse.email);
console.log("full name is",appleAuthRequestResponse.fullName);
}  
}

您仍然可以使用任何jwt解码器(如jwt解码(从appleAuthrequestResponse提供的identityToken中检索电子邮件

const {identityToken, nonce, email} = appleAuthRequestResponse
const {email} = jwt_decode(identityToken)
console.log(email)

Apple只在第一次登录时返回全名和电子邮件,在接下来的登录时会返回null,因此您需要保存这些数据。

要再次接收这些信息,请转到您的设备设置;Settings > Apple ID, iCloud, iTunes & App Store > Password & Security > Apps Using Your Apple ID,点击你的应用程序,然后点击停止使用Apple ID。你现在可以再次登录,你会收到全名和电子邮件。

来源于此。

最新更新