-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
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.