Skip to content

[google_sign_in] initialize shouldn't be called multiple times #171746

@feinstein

Description

@feinstein

Steps to reproduce

I am updating to google_sign_in 7.1.0 and I was trying to find out in the docs if it was safe to call initialize multiple times, or if I have to protect against it. This is not defined in the docs, so I instead looked at the source-code and found this:

 Future<void> initialize({
    String? clientId,
    String? serverClientId,
    String? nonce,
    String? hostedDomain,
  }) async {
    await GoogleSignInPlatform.instance.init(InitParameters(
      clientId: clientId,
      serverClientId: serverClientId,
      nonce: nonce,
      hostedDomain: hostedDomain,
    ));

    final Stream<AuthenticationEvent>? platformAuthEvents =
        GoogleSignInPlatform.instance.authenticationEvents;
    if (platformAuthEvents == null) {
      _createAuthenticationStreamEvents = true;
    } else {
      unawaited(platformAuthEvents.forEach(_translateAuthenticationEvent));
    }
  }

I assume that if I call initialize for a second time, there's a risk the else clause will be called, which will then create a new forEach processing the Stream. Thus each new initialize call could create a new, permanent forEach and thus for each new authentication event, multiple new translated events would be added into the streams.

Expected results

Either make initialize safe to be called multiple times, or state in the docs that it shouldn't.

Actual results

From a source-code analysis, it seems that calling initialize multiple times could lead to duplicated items emitted by the streams.

Metadata

Metadata

Labels

P1High-priority issues at the top of the work listp: google_sign_inThe Google Sign-In pluginpackageflutter/packages repository. See also p: labels.r: fixedIssue is closed as already fixed in a newer versionteam-ecosystemOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions