обещание отклонения пользователя не аутентифицировано в firebase - PullRequest
0 голосов
/ 01 апреля 2020

import React from 'react'
import firebase from 'firebase';
import fire from '../fire';
import { StyleSheet, Text, Alert, View, Button,AsyncStorage} from 'react-native'
import { CheckBox } from 'native-base';
import * as Google from 'expo-google-app-auth';
export default class SignUp extends React.Component {

  state = { user: null ,check:false};
   isUserEqual=(googleUser, firebaseUser)=> {
    if (firebaseUser) {
      var providerData = firebaseUser.providerData;
      console.log(providerData,"providerData")
      for (var i = 0; i < providerData.length; i++) {
        if (providerData[i].providerId === firebase.auth.GoogleAuthProvider.PROVIDER_ID &&
            providerData[i].uid === googleUser.getBasicProfile().getId()) {
          // We don't need to reauth the Firebase connection.
          return true;
        }
      }
    }
    return false;
  }
   onSignIn=(googleUser)=> {
    console.log('Google Auth Response', googleUser);
    // We need to register an Observer on Firebase Auth to make sure auth is initialized.
    var unsubscribe = firebase.auth().onAuthStateChanged((firebaseUser)=> {
      unsubscribe();
      // Check if we are already signed-in Firebase with the correct user.
      if (!this.isUserEqual(googleUser, firebaseUser)) {
        // Build Firebase credential with the Google ID token.


        //getting error here 


        var credential = firebase.auth.GoogleAuthProvider.credential(
          googleUser.id_token,
          googleUser.accessToken
          );
          firebase.auth().signInWithCredential(credential)

        // Sign in with credential from the Google user.
        firebase.auth().signInWithCredential(credential).catch(function(error) {
          // Handle Errors here.
          var errorCode = error.code;
          var errorMessage = error.message;
          // The email of the user's account used.
          var email = error.email;
          // The firebase.auth.AuthCredential type that was used.
          var credential = error.credential;
          // ...
        });
      } else {
        console.log('User already signed-in Firebase.');
      }
    }
    );
  }
    signInWithGoogleAsync=async()=>{
    try {
      const result = await Google.logInAsync({
        behavior:'web',
        androidClientId: "**************************",

        scopes: ['profile', 'email'],
      });

      if (result.type === 'success') {
        this.onSignIn(result);
        return result.accessToken;
      } else {
        return { cancelled: true };
      }
    } catch (e) {
      return { error: true };
    }
  }




      render(){
        return(
      <View style={styles.container}>
        <Button title="sign in with google" onPress={()=>this.signInWithGoogleAsync()}/>

      </View>
    )
  }
}

Я получаю отклонение обещания для различных учетных данных. Я правильно получаю googleUser, где именно я делаю ошибку, и предупреждение показывает, что импорт ограничен. Перестал ли работать импорт? И если да, то каков будет правильный способ сделать это, пожалуйста, напишите код или, если возможно, скомпонуйте его, я также получу предупреждение за недопустимое поведение

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...