Google Sign in React Native Android Sign in Error

Viewed 738

I am currently using the following module to implement a Google signin: react-native-google-signin.

I create the button and when pressed am able to select a google account to log in with, however upon selecting an account I get the following error: WRONG SIGNIN Error: DEVELOPER_ERROR at new GoogleSigninError It looks as though a user object is not being created upon signin. I followed the tutorial pretty thoroughly, is there something I'm not accounting for? Relevant code:

constructor(props){
    super(props);

    this.state = {
      user: null,
    }
  }

componentDidMount() {
    this._setupGoogleSignin();
  }

_signIn() {
    GoogleSignin.signIn()
    .then((user) => {
      console.log(user);
      this.setState({user: user});
      this.props.navigator.push({
        component: Account
      });
    })
    .catch((err) => {
      console.log('WRONG SIGNIN', err);
    })
    .done();
  }

async _setupGoogleSignin() {
    try {
      await GoogleSignin.hasPlayServices({ autoResolve: true });
      await GoogleSignin.configure({
        webClientId: 'MY-CLIENT-ID',
        offlineAccess: false
      });

      const user = await GoogleSignin.currentUserAsync();
      console.log(user);
      this.setState({user});
    }
    catch(err) {
      console.log("Play services error", err.code, err.message);
    }
  }

Within render:

<GoogleSigninButton
    style={{width: 312, height: 48}}
    size={GoogleSigninButton.Size.Wide}
    color={GoogleSigninButton.Color.Light}
    onPress={() => { this._signIn(); }}/>
1 Answers
 componentDidMount() {
    GoogleSignin.configure({
        webClientId: 'YOUR_GOOGLE_CONSOLE_WEB_CLIENT_ID' ,
        forceConsentPrompt: true, // if you want to show the authorization prompt at each login
    });
}
googleSignInHandler = () => {
    GoogleSignin.hasPlayServices()
    .then(res => {
        GoogleSignin.signIn()
        .then(res => {
            console.log(res);
        })
        .catch(err => {
            console.log(err.code);
        });
    })
    .catch(err => {
        console.log(err.message);
    });
}
render() {
    return (
        <View style={styles.container}>
            <GoogleSigninButton
                style={{ width: 48, height: 48 }}
                size={GoogleSigninButton.Size.Icon}
                color={GoogleSigninButton.Color.Dark}
                onPress={this.googleSignInHandler}
            />
        </View>
    );
}
Related