Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't log back in after logging out: "This account already exists on your device" #278

Closed
Robo-Rin opened this issue Aug 17, 2017 · 1 comment

Comments

@Robo-Rin
Copy link

Robo-Rin commented Aug 17, 2017

I'm able to sign in just fine, but when I sign out and attempt to sign in again it says "This account already exists on your device". I'm never given an option to sign in from an existing account. What am I doing wrong?

Here's my setup:

import React, { Component } from 'react';
import { Alert, Button, Image, Text, View } from 'react-native';
import {GoogleSignin, GoogleSigninButton} from 'react-native-google-signin';

export default class LoginScreen extends Component{

  constructor(props){
    super(props);
    this.state = {
      user: null
    }
  }

  componentDidMount() {
    this._setupGoogleSignin().then(() => console.log('Mounted & Google setup complete.'));
  }

  async _setupGoogleSignin() {
    try {
      await GoogleSignin.hasPlayServices({ autoResolve: true });
      await GoogleSignin.configure({
        webClientId: '[my app id].apps.googleusercontent.com',
        hostedDomain: 'somedomain.com'
      });

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

  _signIn() {
    GoogleSignin.signIn()
      .then((user) => {
        this.setState({user: user});
        console.log('Signed in');
        console.log('User: ',user);
      })
      .catch((err) => {
        console.log('WRONG SIGNIN', err);
      })
      .done();
  }

  _signOut() {
    GoogleSignin.revokeAccess().then(() => GoogleSignin.signOut()).then(() => {
        this.setState({user: null});
        console.log('Signed out');
      })
      .done();
  }

  render(){

    if (!this.state.user){
      return (
        <View style={{flex: 1}}>
          <View style={{flex: 1.5, alignItems: 'center', justifyContent: 'center', marginTop: 40}}>
            <Image
              style={{width: 156, height: 156, resizeMode: 'contain'}}
              source={require('../../assets/img/google_logo1600.png')} />
            <Text style={{fontSize: 32, fontWeight: 'bold'}}>
              Google Identity
            </Text>
            <Text style={[{fontSize: 15, paddingTop: 5}]}>
              To continue, please sign-in.
            </Text>
          </View>
          <View style={{flex: 1, alignItems: 'center', justifyContent: 'center', marginBottom: 40}}>
            <GoogleSigninButton
              style={{width: 312, height: 48}}
              size={GoogleSigninButton.Size.Wide}
              color={GoogleSigninButton.Color.Light}
              onPress={() => this._signIn()}/>
          </View>
        </View>
      );
    } else {
      return (
        <View style={{flex: 1}}>
          <View style={{flex: 1, alignItems: 'center', justifyContent: 'center', marginBottom: 40}}>
            <Button style={{width: 312, height: 48, backgroundColor: '#4385F2', color: 'white'}} title="Log Out" onPress={() => this._signOut()} />
          </View>
        </View>
      )
    }

  }
}

Thanks!

@Robo-Rin
Copy link
Author

Robo-Rin commented Aug 18, 2017

I just had to remove the hostedDomain option. Looks like the domain you choose to enter here excludes it from the list of google accounts to select from for logging in again.

Still seeking help for using hostedDomain in #277

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant