首页 > 解决方案 > 世博苹果登录反应原生返回空值

问题描述

我已经在我的 react 本机应用程序中实现了苹果登录。有时它起作用,有时它不起作用。

当它不工作时,它会返回所有 null 用户值,如下所示:

{
  "authorizationCode": "123456789omitted",
  "email": null,
  "fullName": Object {
    "familyName": null,
    "givenName": null,
    "middleName": null,
    "namePrefix": null,
    "nameSuffix": null,
    "nickname": null,
  },
  "identityToken": "987654321omitted",
  "realUserStatus": 1,
  "state": null,
  "user": "192837465omitted",
}

为什么会这样?

<AppleAuthentication.AppleAuthenticationButton
  buttonType={AppleAuthentication.AppleAuthenticationButtonType.SIGN_IN}
  buttonStyle={AppleAuthentication.AppleAuthenticationButtonStyle.BLACK}
  cornerRadius={5}
  style={{
    width: Constant.width * 0.92,
    height: 44,
  }}
  onPress={async () => {
    try {
      setAppleLoggingIn(true);
      const credential = await AppleAuthentication.signInAsync({
        requestedScopes: [
          AppleAuthentication.AppleAuthenticationScope.FULL_NAME,
          AppleAuthentication.AppleAuthenticationScope.EMAIL,
        ],
      });
      // signed in
      onSignIn(credential);//signs in user via firebase
      setAppleLoggingIn(false);
    } catch (e) {
      if (e.code === "ERR_CANCELED") {
        // handle that the user canceled the sign-in flow
        setAppleLoggingIn(false);
        return {cancelled: true};
      } else {
        // handle other errors
        setAppleLoggingIn(false);
        return {error: true};
      }
    }
  }}
/>

我认为这与这个问题有关,但我从未阻止该应用程序访问我的苹果 ID……当它请求权限时,我总是“接受”。在苹果身份验证期间获取电子邮件 ID 值 null 作为响应

标签: react-nativefirebase-authenticationexpoapple-sign-in

解决方案


Apple Sign In 仅在首次登录(注册)时发送用户信息。之后,由您来存储它们并在用户再次登录时重复使用它们。


推荐阅读