Skip to content

Instantly share code, notes, and snippets.

@csells
Created December 8, 2021 02:18
Show Gist options
  • Save csells/3f874c579ecb080acf7f029b01d14589 to your computer and use it in GitHub Desktop.
Save csells/3f874c579ecb080acf7f029b01d14589 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutterfire_ui/auth.dart';
import 'firebase_options.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
runApp(MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) => MaterialApp(
home: AuthenticationGate(),
);
}
class AuthenticationGate extends StatelessWidget {
const AuthenticationGate({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) => StreamBuilder<User?>(
stream: FirebaseAuth.instance.authStateChanges(),
builder: (context, snapshot) {
// User is not signed in - show a sign-in screen
if (!snapshot.hasData) {
return SignInScreen(
providerConfigs: [
EmailProviderConfiguration(),
GoogleProviderConfiguration(
clientId: 'xxxx-xxxx.apps.googleusercontent.com',
),
],
);
}
return HomePage(); // show your app’s home page after login
},
);
}
@gauravstylit-gif
Copy link

Hi,
Did this work, my google sign in does not do anything. It just validates and brings me back to the sign in page. Is there something that i missed.
Also where did u get the client id from?

Thanks a ton

@csells
Copy link
Author

csells commented Jan 13, 2022

Check out the flutterfire_ui plugin and it's support for Google Sign-in: https://firebase.flutter.dev/docs/ui/auth/configuring-providers#google

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment