在 React Native 中使用 Apple 登录返回 null

Sign in with Apple in React Native returning null

我在 React Native 中使用 Apple 登录时遇到问题。起初它返回带有值的电子邮件和名称,但在第二次尝试中它现在返回 null。

第一次尝试:

"email": c@gmail.com, "fullName": {"familyName": admin, "givenName": admin, "middleName": null, "namePrefix": null, "nameSuffix": null, "nickname": null},

第二次尝试:

"email": null, "fullName": {"familyName": null, "givenName": null, "middleName": null, "namePrefix": null, "nameSuffix": null, "nickname": null},

如何防止这种情况发生以及如何使用注销?谢谢!

使用 Sign in with Apple,您只会在首次登录时获得 email/name。然后存储该信息是您的责任。来源:

The identification servers return the user status only when the user first uses Sign in with Apple with your app. Subsequent attempts don’t return any information for this user status, such as after a disconnect and reconnect occurs or from other devices.

https://developer.apple.com/documentation/sign_in_with_apple/sign_in_with_apple_rest_api/authenticating_users_with_sign_in_with_apple

另外:https://developer.apple.com/forums/thread/121496

就注销而言,您 不必 使用 Sign in With Apple 执行此操作。如果您将凭据存储在设备上,则应从存储它们的任何地方清除它们。此外,如果您正在使用其他服务(如 Firebase)的凭据,您当然可以注销该服务。

你没有说明你使用的是什么库,但如果它是 react-native-apple-authentication,你可能想参考这个关于注销行为的线程:https://github.com/invertase/react-native-apple-authentication/issues/10#issuecomment-611532131

如果在 iOS 设备上,用户可以通过“设置”应用撤销“使用 Apple 登录”访问权限。另请参阅此相关的 SO 问题:

苹果只会给第一次登录用户的用户名和邮箱,所以我们必须将用户数据存储到我们数据源的web服务器上,以便从auth id中获取用户数据。否则,我们必须从苹果登录设置中删除日志以重新获取用户数据。