React native 登录时未在apple身份验证中获取用户详细信息(React Native)?

React native 登录时未在apple身份验证中获取用户详细信息(React Native)?,react-native,user-data,React Native,User Data,我需要苹果登录时获取用户数据的帮助。我一直在尝试使用apple身份验证(React Native)登录。但是我没有得到任何用户的详细信息,所以我不能继续做剩下的事情。因此,有人能帮我解决我在代码中犯的错误吗。 导入的库: 导入{appleAuth,AppleButton, AppleAuthRequestOperation, AppleAuthRequestScope, AppleAuthCredentialState, AppleAuthError,}来自“@invertase/react n

我需要苹果登录时获取用户数据的帮助。我一直在尝试使用apple身份验证(React Native)登录。但是我没有得到任何用户的详细信息,所以我不能继续做剩下的事情。因此,有人能帮我解决我在代码中犯的错误吗。

导入的库:

导入{appleAuth,AppleButton, AppleAuthRequestOperation, AppleAuthRequestScope, AppleAuthCredentialState, AppleAuthError,}来自“@invertase/react native apple authentication”; 从“jwt解码”导入jwt_解码

export default class AppleLogin extends Component {
    constructor() {
        super();
        this.authCredentialListener = null;
        this.user = null;
        this.state = {
          credentialStateForUser: -1,
        }
      }
      componentDidMount() {
       
        this.authCredentialListener = appleAuth.onCredentialRevoked(async () => {
          console.log('Credential Revoked');
          this.fetchAndUpdateCredentialState().catch(error =>
            this.setState({ credentialStateForUser: `Error: ${error.code}` }),
          );
        });
    
        this.fetchAndUpdateCredentialState()
          .then(res => this.setState({ credentialStateForUser: res }))
          .catch(error => this.setState({ credentialStateForUser: `Error: ${error.code}` }))
      }
    
      componentWillUnmount() {
      
        this.authCredentialListener();
      }
    
      signIn = async () => {
        console.warn('Beginning Apple Authentication');
    
        // start a login request
        try {
          const appleAuthRequestResponse = await appleAuth.performRequest({
            requestedOperation: appleAuth.Operation.LOGIN,
            requestedScopes: [
              appleAuth.Scope.EMAIL,
              appleAuth.Scope.FULL_NAME,
            ],
          });
        
          console.log('appleAuthRequestResponse', appleAuthRequestResponse);

          const {
         newUser,
            email,
            nonce,
            identityToken,
            realUserStatus /* etc */,
          } = jwt_decode(appleAuthRequestResponse.identityToken);
          alert("appleAuthRequestResponse2",email,user)
          this.user = newUser;
          alert("appleAuthRequestResponse 3",this.user )
          this.fetchAndUpdateCredentialState()
            .then(res => {alert('res',res),
            this.setState({ credentialStateForUser: res })})
            .catch(error =>
              this.setState({ credentialStateForUser: `Error: ${error.code}` }),
            );
    
    
          if (realUserStatus === appleAuth.UserStatus.LIKELY_REAL) {
            console.log("I'm a real person!");
          }
    
          console.warn(`Apple Authentication Completed, ${this.user}, ${email}`);
        } catch (error) {
          if (error.code === appleAuth.Error.CANCELED) {
            console.warn('User canceled Apple Sign in.');
          } else {
            console.error(error);
          }
        }
      };
    
      fetchAndUpdateCredentialState = async () => {
        if (this.user === null) {
          this.setState({ credentialStateForUser: 'N/A' });
        } else {
          const credentialState = await appleAuth.getCredentialStateForUser(this.user);
          if (credentialState === appleAuth.State.AUTHORIZED) {
            this.setState({ credentialStateForUser: 'AUTHORIZED' });
          } else {
            this.setState({ credentialStateForUser: credentialState });
          }
        }
      }
    login= async () => {
      const appleAuthRequestResponse = await appleAuth.performRequest({
        requestedOperation: AppleAuthRequestOperation.LOGIN,
        requestedScopes: [AppleAuthRequestScope.EMAIL, AppleAuthRequestScope.FULL_NAME],
      });
    
      const credentialState = await appleAuth.getCredentialStateForUser(appleAuthRequestResponse.user);
    
      if (credentialState === AppleAuthCredentialState.AUTHORIZED) {
        alert("get cridential",credentialState)
     
      }
      
      // catch signIn errors
   
        if (error.code === AppleAuthError.CANCELED) // do something
        {
          alert("errr",error)
        }
    }```