Skip to content

Commit a3ec71f

Browse files
committed
fix(oauth): ensure provider buttons trigger AuthStateChangeAction
1 parent b61433d commit a3ec71f

6 files changed

Lines changed: 148 additions & 49 deletions

File tree

packages/firebase_ui_oauth/lib/src/oauth_provider_button_base.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,10 @@ class _OAuthProviderButtonBaseState extends State<OAuthProviderButtonBase>
155155
provider.auth = widget.auth ??
156156
FirebaseAuthProvider.findAuth(context) ??
157157
fba.FirebaseAuth.instance;
158-
provider.authListener = this;
158+
159+
if (!widget.overrideDefaultTapAction) {
160+
provider.authListener = this;
161+
}
159162
}
160163

161164
void _signIn() {

packages/firebase_ui_oauth/test/flutterfire_ui_oauth_test.dart

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,5 +221,73 @@ void main() {
221221

222222
expect(find.byType(LayoutFlowAwarePadding), findsOneWidget);
223223
});
224+
225+
testWidgets('triggers AuthStateChangeAction via AuthFlowBuilder', (tester) async {
226+
final actionCalled = <SignedIn>[];
227+
final provider = TestOAuthProvider();
228+
final auth = MockAuth();
229+
provider.auth = auth;
230+
231+
await tester.pumpWidget(
232+
DefaultAssetBundle(
233+
bundle: FakeAssetBundle(),
234+
child: MaterialApp(
235+
home: Scaffold(
236+
body: FirebaseUIActions(
237+
actions: [
238+
AuthStateChangeAction<SignedIn>((context, state) {
239+
actionCalled.add(state);
240+
}),
241+
],
242+
child: Center(
243+
child: AuthFlowBuilder<OAuthController>(
244+
provider: provider,
245+
auth: auth,
246+
builder: (context, state, ctrl, child) {
247+
return OAuthProviderButtonBase(
248+
provider: provider,
249+
auth: auth,
250+
label: 'Sign in with Test provider',
251+
loadingIndicator: const CircularProgressIndicator(),
252+
onTap: () => ctrl.signIn(Theme.of(context).platform),
253+
overrideDefaultTapAction: true, // Simulating the fix
254+
);
255+
},
256+
),
257+
),
258+
),
259+
),
260+
),
261+
),
262+
);
263+
264+
await tester.tap(find.text('Sign in with Test provider'), warnIfMissed: false);
265+
await tester.pump();
266+
267+
expect(actionCalled, hasLength(1));
268+
});
224269
});
225270
}
271+
272+
class TestOAuthProvider extends FakeOAuthProvider {
273+
@override
274+
void mobileSignIn(AuthAction action) {
275+
authListener.onBeforeSignIn();
276+
authListener.onSignedIn(MockUserCredential());
277+
}
278+
}
279+
280+
class MockAuth extends Fake implements fba.FirebaseAuth {
281+
@override
282+
fba.User? get currentUser => null;
283+
}
284+
285+
class MockUserCredential extends Fake implements fba.UserCredential {
286+
@override
287+
fba.User? get user => MockUser();
288+
@override
289+
fba.AdditionalUserInfo? get additionalUserInfo => null;
290+
}
291+
292+
class MockUser extends Fake implements fba.User {}
293+

packages/firebase_ui_oauth_apple/lib/firebase_ui_oauth_apple.dart

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,20 +104,27 @@ class _AppleSignInButton extends StatelessWidget {
104104

105105
@override
106106
Widget build(BuildContext context) {
107-
return OAuthProviderButtonBase(
107+
return AuthFlowBuilder<OAuthController>(
108108
provider: provider,
109-
label: label,
110-
onTap: onTap,
111-
loadingIndicator: loadingIndicator,
112-
isLoading: isLoading,
113109
action: action,
114-
auth: auth ?? fba.FirebaseAuth.instance,
115-
onDifferentProvidersFound: onDifferentProvidersFound,
116-
onSignedIn: onSignedIn,
117-
overrideDefaultTapAction: overrideDefaultTapAction,
118-
size: size,
119-
onError: onError,
120-
onCancelled: onCanceled,
110+
auth: auth,
111+
builder: (context, state, ctrl, child) {
112+
return OAuthProviderButtonBase(
113+
provider: provider,
114+
label: label,
115+
onTap: () => ctrl.signIn(Theme.of(context).platform),
116+
loadingIndicator: loadingIndicator,
117+
isLoading: state is SigningIn || state is CredentialReceived,
118+
action: action,
119+
auth: auth ?? fba.FirebaseAuth.instance,
120+
onDifferentProvidersFound: onDifferentProvidersFound,
121+
onSignedIn: onSignedIn,
122+
overrideDefaultTapAction: true,
123+
size: size,
124+
onError: onError,
125+
onCancelled: onCanceled,
126+
);
127+
},
121128
);
122129
}
123130
}

packages/firebase_ui_oauth_facebook/lib/firebase_ui_oauth_facebook.dart

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -114,20 +114,27 @@ class _FacebookSignInButton extends StatelessWidget {
114114

115115
@override
116116
Widget build(BuildContext context) {
117-
return OAuthProviderButtonBase(
117+
return AuthFlowBuilder<OAuthController>(
118118
provider: provider,
119-
label: label,
120-
onTap: onTap,
121-
loadingIndicator: loadingIndicator,
122-
isLoading: isLoading,
123119
action: action,
124-
auth: auth ?? fba.FirebaseAuth.instance,
125-
onDifferentProvidersFound: onDifferentProvidersFound,
126-
onSignedIn: onSignedIn,
127-
overrideDefaultTapAction: overrideDefaultTapAction,
128-
size: size,
129-
onError: onError,
130-
onCancelled: onCanceled,
120+
auth: auth,
121+
builder: (context, state, ctrl, child) {
122+
return OAuthProviderButtonBase(
123+
provider: provider,
124+
label: label,
125+
onTap: () => ctrl.signIn(Theme.of(context).platform),
126+
loadingIndicator: loadingIndicator,
127+
isLoading: state is SigningIn || state is CredentialReceived,
128+
action: action,
129+
auth: auth ?? fba.FirebaseAuth.instance,
130+
onDifferentProvidersFound: onDifferentProvidersFound,
131+
onSignedIn: onSignedIn,
132+
overrideDefaultTapAction: true,
133+
size: size,
134+
onError: onError,
135+
onCancelled: onCanceled,
136+
);
137+
},
131138
);
132139
}
133140
}

packages/firebase_ui_oauth_google/lib/firebase_ui_oauth_google.dart

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -118,20 +118,27 @@ class _GoogleSignInButton extends StatelessWidget {
118118

119119
@override
120120
Widget build(BuildContext context) {
121-
return OAuthProviderButtonBase(
121+
return AuthFlowBuilder<OAuthController>(
122122
provider: provider,
123-
label: label,
124-
onTap: onTap,
125-
loadingIndicator: loadingIndicator,
126-
isLoading: isLoading,
127123
action: action,
128-
auth: auth ?? fba.FirebaseAuth.instance,
129-
onDifferentProvidersFound: onDifferentProvidersFound,
130-
onSignedIn: onSignedIn,
131-
overrideDefaultTapAction: overrideDefaultTapAction,
132-
size: size,
133-
onError: onError,
134-
onCancelled: onCanceled,
124+
auth: auth,
125+
builder: (context, state, ctrl, child) {
126+
return OAuthProviderButtonBase(
127+
provider: provider,
128+
label: label,
129+
onTap: () => ctrl.signIn(Theme.of(context).platform),
130+
loadingIndicator: loadingIndicator,
131+
isLoading: state is SigningIn || state is CredentialReceived,
132+
action: action,
133+
auth: auth ?? fba.FirebaseAuth.instance,
134+
onDifferentProvidersFound: onDifferentProvidersFound,
135+
onSignedIn: onSignedIn,
136+
overrideDefaultTapAction: true,
137+
size: size,
138+
onError: onError,
139+
onCancelled: onCanceled,
140+
);
141+
},
135142
);
136143
}
137144
}

packages/firebase_ui_oauth_twitter/lib/firebase_ui_oauth_twitter.dart

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -118,20 +118,27 @@ class _TwitterSignInButton extends StatelessWidget {
118118

119119
@override
120120
Widget build(BuildContext context) {
121-
return OAuthProviderButtonBase(
121+
return AuthFlowBuilder<OAuthController>(
122122
provider: provider,
123-
label: label,
124-
onTap: onTap,
125-
loadingIndicator: loadingIndicator,
126-
isLoading: isLoading,
127123
action: action,
128-
auth: auth ?? fba.FirebaseAuth.instance,
129-
onDifferentProvidersFound: onDifferentProvidersFound,
130-
onSignedIn: onSignedIn,
131-
overrideDefaultTapAction: overrideDefaultTapAction,
132-
size: size,
133-
onError: onError,
134-
onCancelled: onCanceled,
124+
auth: auth,
125+
builder: (context, state, ctrl, child) {
126+
return OAuthProviderButtonBase(
127+
provider: provider,
128+
label: label,
129+
onTap: () => ctrl.signIn(Theme.of(context).platform),
130+
loadingIndicator: loadingIndicator,
131+
isLoading: state is SigningIn || state is CredentialReceived,
132+
action: action,
133+
auth: auth ?? fba.FirebaseAuth.instance,
134+
onDifferentProvidersFound: onDifferentProvidersFound,
135+
onSignedIn: onSignedIn,
136+
overrideDefaultTapAction: true,
137+
size: size,
138+
onError: onError,
139+
onCancelled: onCanceled,
140+
);
141+
},
135142
);
136143
}
137144
}

0 commit comments

Comments
 (0)