Why _syncUserWithStateAsync is used twice in expo-google-sign-in

I use Expo SDK 39 for my project. I use expo-google-sign-in and I do not have any problems with it. It works as a charm. However, I do need a clarification why _syncUserWithStateAsync is used twice in GoogleSignIn.

1 on mounting the app:

 componentDidMount() {
    this.initAsync();
  }

  initAsync = async () => {
    await GoogleSignIn.initAsync({
      // You may ommit the clientId when the firebase `googleServicesFile` is configured
      clientId: '<YOUR_IOS_CLIENT_ID>',
    });
    this._syncUserWithStateAsync();
  };

Next, on login:

  signInAsync = async () => {
    try {
      await GoogleSignIn.askForPlayServicesAsync();
      const { type, user } = await GoogleSignIn.signInAsync();
      if (type === 'success') {
        this._syncUserWithStateAsync();
      }
    } catch ({ message }) {
      alert('login: Error:' + message);
    }
  };

The reason I’m asking is because, if this function is invoked twice, means that it will try to sign in to Google twice and setting the state twice.

Any experts here? Do share what you think. Thank you.

1 Like

I don’t use it but by the looks of it, seems that the first sync (on mount) is done for the auto login (in case you are already signed in).

And secondly, the signIn method is for when a user actively taps on the login.

Regards

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.